Preface
I have summarized the design patterns recently. This article will give you an overall introduction to the design patterns.
Body 1. Definition
The design pattern is a code design solution for a specific type of problem. It is a summary of the experience in code design.
2. Role
- Improve code reuse rate and reduce development costs and cycles
- Improve code maintainability and scalability
- Make the code more elegant and readable
- Make code easier to be understood by others
3. Design Principles
The following object-oriented design principles must be observed when designing a design pattern:
- Single Responsibility Principle(
SRP
): For a class, there should be only one reason for its change.
- Principle of opening/closing(
ASD
): Classes, modules, and functions can be expanded, but cannot be modified.
- Rys replacement principle(
LSP
): All objects that reference the base class (parent class) must be transparently used.
- Dependency inversion principle(
DIP
): High-Level modules should not depend on low-level modules. Both of them should depend on abstraction. Abstraction should not depend on details, but on abstraction.
- Dumit principles(
LOD
): A software entity should interact with other entities as little as possible.
- Interface isolation principle(
ISP
): The dependency of one class on another class should be built on the smallest interface.
4. Design Pattern Classification
Common23
TypeDesign ModeIn general, there are three categories:Creation Mode,Structural ModeAndBehavior mode.
Creation ModeFive methods: Factory method mode, abstract factory mode, Singleton mode, builder mode, and prototype mode.
Structural Mode(7 in total): adapter mode, decorator mode, proxy mode, appearance mode, bridging mode, combination mode, and meta mode.
Behavior mode(11 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.
Shows the three types of design patterns and their classifications:
Summary
This article gives a general introduction to the definition of design patterns. Next I will analyze several common design patterns in detail.
Welcome to the public account: the technology Stack
This account will continue to share back-end technologies, including virtual machine basics, multi-thread programming, high-performance frameworks, asynchronous, cache and messaging middleware, distributed and microservice, architecture learning and advanced learning materials and articles.
One design pattern per day (1)-Overview