What is the design pattern?
Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used to reuse code, make code easier for others to understand, and ensure code reliability. There is no doubt that design patterns in their own systems are multi-win, design patterns so that code is truly engineering, design patterns are the cornerstone of software engineering, as the structure of the building.
Overall, the design pattern is divided into 3 major categories totaling 23 kinds:
1, create a model, a total of 5
Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode
2. Structure mode, total 7 kinds
Adapter mode, adorner mode, appearance mode, bridging mode, combined mode, enjoy meta mode
3, behavioral mode, a total of 11
Policy mode, template method mode, observer pattern, iterator mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode
There are actually two classes, the concurrency pattern and the thread pool pattern.
Six Principles of design pattern
1. Open and closed principle OCP
The open and closed principle is that opening to the extension and closing the modification . When the program needs to be extended, it is not possible to modify the original code, which is also to make the program more extensible, easy to upgrade and maintenance.
2, the Richter substitution principle LSP
Replace a base class object with its subclass object in the software, and the program will not produce any errors or exceptions, which in turn is not true. If a software entity is using a subclass object, it must not be able to use the base class object. The procedural manifestation of the principle of substitution of the Richter scale is to use the base class type to define the object in the program, and then determine its subclass type at run time, substituting the parent class with the subclass object.
3. Control reversal Principle IOC
Programming for interfaces, relying on abstraction rather than on specific
4. Interface Isolation principle ISP
Using multiple isolated interfaces is better than using a single interface
5, Dimitri Law DP
An entity should interact with other entities as little as possible, making the system function modules relatively independent
6. Principle of synthetic reuse
Try to use the combination/aggregation approach instead of using inheritance
Three keywords in a design
1. Abstraction
Extracting common and essential features in many things, discarding non-essential features, is abstraction. The process of abstraction is also a process of tailoring, which, when abstracted, is different, depending on what angle it is abstracted from. The abstract angle depends on the purpose of the analysis problem.
2, realization of the
The concrete implementation of abstract class is realization.
An instance of a class is an instantiation of this class, and a concrete subclass is an instantiation of its abstract superclass.
3. Decoupling
This is more important, usually we always agreed that the code should be "high cohesion, low coupling", then what is the coupling?
The so-called coupling is a strong association of the behavior of two entities . and removing the strong association between them is decoupling. Decoupling is to untie the coupling between abstraction and implementation, or to change the strong association between them into weak associations.
The so-called Strong Association, refers to the compile time has been determined, can not be dynamically changed during the runtime of the Association, so-called Weak association, it can be dynamically determined and dynamic change in the run time of the association . From this definition, the inheritance relationship is strongly correlated, and the aggregation relationship is a weak association.
Java Design Pattern 1: An Introduction to design patterns