I. Classification of design Patterns
Design patterns fall into three main categories:
1. Create pattern, total five kinds: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.
2. structure mode, a total of seven kinds: Adapter mode, adorner mode, agent mode, appearance mode, bridge mode, combined mode, enjoy meta mode.
3. Behavioral mode, a total of 11 kinds: Strategy mode, template method mode, observer mode, iterative sub-mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode.
In fact, there are two types: concurrency mode and thread pool mode. Use a picture to describe it as a whole:
the six principles of design pattern
general principle: Opening and closing principle (Open Close Principle)
The open and closed principle is to say to the expansion opening, to modify the closure . When the program needs to expand, not to modify the original code, but to extend the original code, to achieve a hot plug effect. So a nutshell is: In order to make the program good extensibility, easy to maintain and upgrade. To achieve such an effect, we need to use interfaces and abstract classes, and so on, which we will mention in the specific design later on.
1. Single Duty principle:do not have more than one cause of class changes, that is, each class should implement a single responsibility, if not, the class should be split.
2, the Richter replacement principle (Liskov Substitution Principle)
One of the basic principles of object-oriented design of the Richter substitution principle. The Richter substitution principle says that where any base class can appear, subclasses must be able to appear . LSP is the cornerstone of inheritance reuse, only if the derived class can replace the base class, the function of the Software unit is not affected, the base class can be really reused, and the derived class can also add new behavior on the basis of the base class. The principle of substitution on the Richter scale is a supplement to the principle of "open-closed". The key step in implementing the "open-close" principle is abstraction. The inheritance of the base class and subclass is the concrete implementation of abstraction, so the principle of the substitution of the Richter scale is the specification of the concrete steps to realize the abstraction.
In the Richter substitution principle, subclasses do not override and overload the methods of the parent class as much as possible. Because the parent class represents a well-defined structure, the sub-class should not arbitrarily destroy it by interacting with the outside world through this canonical interface.
3. Dependence reversal principle (dependence inversion Principle)
This is the basis of the open and close principle, the specific content: interface-oriented programming, dependent on the abstract and not dependent on the specific. When writing code, a specific class is used, not interacting with a specific class, but interacting with the upper interface of a specific class.
4. Interface Isolation principle (Interface segregation Principle)
This principle means that there is no way for subclasses to be implemented in each interface, and if not, the interface should be split. Using multiple isolated interfaces is better than using a single interface (multiple interface methods to assemble to one interface).
5, Dimitri Law (least known principle) (Demeter Principle)
It means that a class knows as little as possible about the classes it relies on. This means that no matter how complex a dependent class is, the logic should be encapsulated inside the method and provided externally through the public method. This way, the class can be minimized when the dependent class changes.
The least known principle is another way of saying it: communicate only with direct friends. As long as there is a coupling relationship between classes, it is called a friend relationship. Coupling is divided into dependency, association, aggregation, combination and so on. We call the class that appears as a member variable, method parameter, method return value as a direct friend. Local variables, temporary variables are not direct friends. We ask unfamiliar classes not to appear as local variables in the class.
6. Synthetic multiplexing principles (Composite reuse Principle)
The principle is to try to use the composition/aggregation approach first, rather than using inheritance.
Full analysis of DM (i)