Reading abstract-big talk Design Model

Source: Internet
Author: User
Chapter 2 Policy Mode

Combination of policy mode and factory method:

In the Basic Policy mode, the responsibility for implementing specific policies selected is borne by the client user, which does not relieve the pressure on the client to select judgment; after combining the policy mode with the simple factory mode (adding the factory method feature to the context class), the responsibility for selecting the specific implementation is also borne by the context, this minimizes the burden on the client.

Chapter IV principle of openness and Closure

In the face of demand changes, program changes are implemented by adding new Code, rather than changing the existing code-this is the essence of the "development, closed principle.

Chapter 6 decoration Mode

The decoration mode distinguishes the core functions of the class from the decorative functional area, and eliminates possible code duplication when combining several decorative functions.


Chapter 8 factory methods ( Factory method )

Differences between factory methods and simple factories:

The maximum advantage of the simple factory mode is that the factory class contains the necessary logical judgment, and the appropriate class can be dynamically instantiated based on the conditions given by the client. for the client, remove dependencies with specific products. However, the problem is that to add new products, you must modify the logic judgment part (switch/case) in the factory class, which violates the "closed and open principle"

The biggest difference between a simple factory and a factory method is that an abstract base class is added to all factory classes in the factory method; in this way, the factory method transfers the logic judgment of the simple factory to the client,

In summary, the factory method overcomes the disadvantages of a simple factory that violates the "Development and Sealing Principle" and maintains the characteristics of the encapsulated object creation process. The disadvantage is that no new product is added, A new factory class is required.

Chapter 9 prototype mode


In the prototype mode, you can dynamically copy the running status of an object without re-initializing the object.

Chapter 10 dimit Law


The dimit rule (the level of detail) is also called the principle of least dependence: If two classes do not need to communicate with each other directly, they should not interact directly; if one class needs to call a method of another class, it can be forwarded by a third party.

The essence of his law is to ensure "low coupling" between classes ".


Chapter 2 Abstract Factory


Dependency injection and reflection

In all scenarios where a simple factory is used, the reflection technology can be used to remove branch statements such as switch, case, or if, to eliminate coupling caused by Branch judgment.


Chapter 2 Singleton

Double-check locking and thread security


Chapter 2 intermediary Mode


Although the division of a system into multiple objects usually increases reusability, the increase in the number of objects connected to each other reduces the reusability, this is because the existence of a large number of connections makes an object unable to work without the support of other objects. The system is represented as an integral whole.

The intermediary mode is a typical application of the "dimit law". Its advantages and disadvantages are derived from centralized control.

Chapter 1 Interpreter Mode


Regular Expressions are typical applications of interpreter mode.


Chapter 4 visitor Mode


The visitor mode is designed to separate operations from data structures. It is most suitable for systems with stable data structures and easy-to-change algorithms and operations, the visitor mode makes operations easier.
The biggest advantage of the visitor mode is that it is easy to add new operations. You only need to add a new visitor. In turn, the disadvantage of the visitor mode is that it is difficult to add new data structures.

Most of the time you do not need the visitor mode, but once you need the visitor mode, it is actually needed.










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.