Summarize 23 design patterns and 23 Design Patterns
There are three types of design patterns:Creation ModeThere are five methods: Factory method mode, abstract factory mode, Singleton mode, builder mode, and prototype mode.Structural ModeThere are seven types: adapter mode, decorator mode, proxy mode, appearance mode, bridging mode, combination mode, and metadata mode.Behavior mode, 11 types in total: rule mode, template method mode, observer mode, iteration sub-mode, responsibility chain mode, command mode, memorandum mode, state mode, visitor mode, intermediary mode, interpreter mode. There are actually two types: Parallel hair mode and Thread Pool Mode.
Six principles of the design model:General principles-open and closed principlesIt is open to extensions and closed to modifications. When the program needs to be expanded, the original code cannot be modified, but the original code must be extended to achieve a hot swapping effect. So in a word, it is easy to maintain and upgrade the program to make it more scalable. To achieve this, we need to use interfaces and abstract classes. We will mention this in the specific design.
1. Single Responsibility PrincipleThere should be no more reasons for class changes, that is to say, each class should have a single responsibility; otherwise, classes should be split.
2. Liskov Substitution Principle)Where any base class can appear, subclass can certainly appear. The lining replacement principle is the cornerstone of inheritance reuse. Only when the primary class can replace the base class and the functions of the software unit are not affected can the base class be reused, the category class can also add new behaviors based on the base class. The Li's replacement principle is a supplement to the "open-closed" principle. The key step for implementing the "open and closed" principle is abstraction. The inheritance relationship between the base class and sub-classes is the specific implementation of abstraction. Therefore, the Li's replacement principle is the standard for the specific steps to implement abstraction. In the Rys replacement principle, subclass methods for parent classes should not be overwritten or overloaded as much as possible. Because the parent class represents a defined structure and interacts with the outside world through this standard interface, the subclass should not destroy it at will.
3. Dependence Inversion Principle)API-Oriented Programming relies on abstraction rather than specifics. When writing code, a specific class is used, instead of interacting with a specific class, it interacts with the upper-layer interface of a specific class.
4. Interface Segregation Principle)Each interface does not have a method that the subclass is not used but must be implemented. Otherwise, the interface should be split. Using multiple isolated interfaces is better than using a single interface (integrating multiple interface methods into one interface.
5. Demeter Principle)The fewer classes that a class depends on, the better. No matter how complex the dependent class is, the logic should be encapsulated inside the method and provided to the external through the public method. In this way, when the dependent class changes, the class can be minimized. Another way of expressing the principle of least understanding is to communicate with direct friends only. As long as there is a coupling relationship between classes, it is called a friend relationship. Coupling can be divided into dependency, association, aggregation, and combination. We call the class that appears as a member variable, method parameter, and method return value as a friend. Local variables and temporary variables are not directly friends. We require a strange class not to appear in the class as a local variable.
6. Composite Reuse Principle)Try to use the synthesis/aggregation method first, instead of the Inheritance Method.
Nine design patterns have been sorted out one after another. The links are as follows. The rest of the patterns will be sorted out one after another, so it is important to understand the design patterns.
Creation Mode: Factory method mode, abstract factory mode, Singleton mode, builder mode, and prototype mode: adapter mode, decorator mode, proxy mode, appearance mode, Bridge Mode, combination mode, and shared-element mode behavior mode: policy mode, template method mode, observer mode, iteration sub-mode, responsibility chain mode, command mode, memorandum mode, state mode, visitor mode, intermediary mode, interpreter mode, there are two types of modes: concurrent hairstyle mode and Thread Pool Mode.
Author: jason0539
Blog: http://blog.csdn.net/jason0539 (reprinted please explain the source)
Scan the QR code to follow my public account