Design Pattern Experience

Source: Internet
Author: User

1. Inheritance is the main means of system evolution, the design pattern is divided into three kinds according to the discussion direction, one is to discuss the relationship between the object and the scene, in order to improve the inheritance, in order to facilitate the system into. Second, the discussion class of the combination, its third, discusses the management of the class tree. The ultimate goal is to provide an evolutionary system with the convenience of optimizing the code structure.

2. Factory methods, prototypes, and the singleton is actually a discussion of the relationship between the object and the scene. The factory method enables class-to-scene code-level isolation and facilitates the independent evolution of classes. The prototype separates the initialization of objects from the use of objects, facilitates the interaction of two different scenarios, and, in fact, restricts the number of times a scene is used on objects from a resource perspective.

The interpreter is also the object-to-scene relationship, factory method production object, interpreter production behavior, similar to some kind of configuration, scripting, to provide the most flexibility for the system.

3. Builders, bridges, combinations, appearances, rewards, chains of responsibility, commands, iterators, intermediaries, memos, observers, status, strategies, and visitors are all in the discussion portfolio.

First of all, there are data and methods in the program, or there is a large class, there are many methods and data, one thing. These things need to be broken down into small classes according to the rules in order to make use of modular management and evolution.

First, according to the scale or evolutionary speed of the division, the evolution of the speed of the original class of different components, the absence of inheritance of several classes, combined together to complete a function.

For example, the builder, belongs to the structure of the volume of the larger, strategic mode, part of the method has more changes, to enjoy the yuan, simply the fixed part and the variable part of the separation, saving resources. Visitors, belonging to the more varied parts extracted out of independent evolution.

Second, according to the function of the split, to achieve some special design requirements, or to achieve a single responsibility. Of course, the separation of responsibility party development is relatively large, more responsibilities, but also an important indicator.

The observer, the observer and the observer have different requirements, state patterns, encapsulation state-related methods, and omit branch statements. Command mode, which encapsulates the invocation of a method. An iterator pattern that encapsulates the data access of a class. Memo mode, encapsulates the overall context of the class, providing recovery support.
Third, after the split will have a relationship problem.

bridging, direct invocation, combination, ease of management, responsibility chain, to achieve the processing process pipeline. The mediator pattern, which loosely couples the relationships of the classes. Appearance mode, which integrates the operation of the caller.

4. Inheritance tree-related

Template method, define framework, subclass implementation function.

The proxy mode, which is used by the agent to decide which child class to use.

Adorner mode, which adds some action before and after the call through inheritance.

An adapter is actually a generalized inheritance that should be used in conjunction with a scene invocation.


All of the above object classes can be replaced by programs, assemblies, and processes.

Design Pattern Experience

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.