Summary of class Link Design Patterns

Source: Internet
Author: User

The previous section briefly learned the rule mode, observer mode, and modifier mode. The three modes are mainly used to process the relationship between classes. The three modes are gradual and progressive, and the subsequent modes can be said to be perfect for the previous mode.

Rule Mode: One-to-one class relationship. The mode has one core and multiple algorithms, but the core can only be used by one of these algorithms. This is also a disadvantage and leads to the observer mode.

Observer Mode: One-to-many class relationship. The mode has one topic and multiple observers. At this time, the topic can hold multiple observations and use the method. However, we can also find that the observer is less reusable and basically bound to a topic.

Decoration Mode: Multi-to-Multi relationship, the model can have multiple decorators and multiple components, and the component may also be a decoration, a decoration can decorate multiple components, a widget can also have multiple decorators.


Each mode has its own limitations, that is, it is suitable for handling problems within a certain range. There is no general mode, but only a solution.

Sort out the problem domains applicable to the three modes]

Rule mode:

1. Multiple classes only show different behaviors, and other struct structures are basically the same, such as wage settlement. The differences between class structures are mostly different in the calculation method.

2. Different algorithms must be used in different situations, or the algorithm implementation method may change as expected.

3. Hide the specific implementation details (keep the core technology in your own hands ).

Observer Mode

1. the abstract individual has two interdependent layers. These objects are encapsulated so that they can be modified at will without affecting the interaction between dependencies.

2. Changes to an object will affect other objects, but you do not know the number of objects to be affected.

3. The object has the ability to notify other objects, but does not know the specific implementation details.

Decoration Mode

1. You need to extend the functions of a class or assign a role to a class.

2. Dynamic extension class functions

3. A large number of functions need to be combined by basic functions

4. one case is that a large number of independent extensions may exist, resulting in a large number of child classes. The other case is that the class definition is hidden or cannot be used to produce child classes.

Summary of class Link Design Patterns

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.