In general, the design model is divided into three categories:
There are five creation modes: Factory method mode, abstract factory mode, Singleton mode, builder mode, and prototype mode.
There are seven structural modes: adapter mode, decorator mode, proxy mode, appearance mode, bridging mode, combination mode, and meta mode.
11 behavior models: 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.
Ii. six principles of the design model
1. Open Close Principle)
The principle of opening/closing is to sayOpen to extension and disable Modification. When the program needs to be expanded, you cannot modify the original code 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.
2. liskov substitution principle)
Liskov substitution principle LSP is one of the basic principles of object-oriented design. In the Rys replacement principle, subclasses can certainly appear where any base class can appear. LSP 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-close" 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. -- From Baidu encyclopedia
3. Dependence inversion principle)
This is the basis of the open/closed principle. The specific content is: True interface programming, dependent on abstraction and not on specifics.
4. Interface segregation principle)
This principle means that using multiple isolated interfaces is better than using a single interface. We can see from this that the design mode is a software design idea, starting from the large-scale software architecture, for the convenience of upgrading and maintenance. So it appears many times above: reducing dependencies and reducing coupling.
5. Demeter Principle)
What is the principle of least understanding? That is to say, an entity should interact with other entities as little as possible so that the system function modules are relatively independent.
6. Composite Reuse Principle)
The principle is to use synthesis/aggregation as much as possible, rather than inheritance.
Basic knowledge of design patterns