Design Patterns
I want to get serious about understanding design patterns. This is the beginning of figuring out what design patterns are.
define
A design pattern is a set of repeatedly used, widely known, catalogued code design lessons.
Why design patterns
For reusable code, make it easier for others to understand and ensure the reliability of the code.
Who designs cow mode like that
The Gang of Four, or GoF, was Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. But they didn’t Design it. They compiled 23 of the most commonly used Design Patterns in a book in 1995: Elements of Reusable Object-oriented Software is called Design Patterns: The Foundations of Reusable Object-oriented Software. It has been proven over time. You must learn it.
How to learn
balabala …
The four most important elements of design pattern are Parttern Name, Problem, Solution, and Consequences. To learn about design patterns, we start with these four elements. Figure it out one by one.
- The schema Name (Parttern Name) is the Name of the schema. Simple and straightforward naming.
- Problems describe when patterns should be used, including problems in the design and why they exist
- The Solution of the framework. Is how to design this pattern. Describes the components of a design pattern, their relationships, their responsibilities, and how they work together, usually through UML class diagrams and core code.
- Effect (Consequences)
Describes the advantages and disadvantages of patterns and trade-offs when using patterns (presentation)
Speaking of which, what framework do you have
In addition to the 23 patterns mentioned by GoF, we should also add a Simple Factory Pattern, which is also very common and Simple. I picked it up right away.
Here’s a preview (reference)
type |
Model name |
Learning difficulty |
Use frequency |
Creation pattern Creational Pattern |
The singleton pattern Singleton Pattern |
U do things being fostered fostered |
U u u u do |
Simple Factory model Simple Factory Pattern |
U u being fostered fostered |
U u u do do |
|
Factory method pattern Factory Method Pattern |
U u being fostered fostered |
U u u u u |
|
Abstract Factory pattern Abstract Factory Pattern |
U u u u do |
U u u u u |
|
The prototype pattern Prototype Pattern |
U u u do do |
U u u do do |
|
Builder model Builder Pattern |
U u u u do |
U u being fostered fostered |
|
Structural mode Structural Pattern |
Adapter mode Adapter Pattern |
U u being fostered fostered |
U u u u do |
The bridge model Bridge Pattern |
U u u do do |
U u u do do |
|
Portfolio model Composite Pattern |
U u u do do |
U u u u do |
|
Decorative pattern Decorator Pattern |
U u u do do |
U u u do do |
|
The appearance model The Facade Pattern |
U do things being fostered fostered |
U u u u u |
|
The flyweight pattern Flyweight Pattern |
U u u u do |
U do things being fostered fostered |
|
The proxy pattern Proxy Pattern |
U u u do do |
U u u u do |
|
Behavioral pattern Behavioral Pattern |
Chain of Responsibility model Chain of Responsibility Pattern |
U u u do do |
U u being fostered fostered |
Command mode Command Pattern |
U u u do do |
U u u u do |
|
Interpreter mode Interpreter Pattern |
U u u u u |
U do things being fostered fostered |
|
Iterator pattern Iterator Pattern |
U u u do do |
U u u u u |
|
The mediator pattern Mediator Pattern |
U u u do do |
U u being fostered fostered |
|
Memo mode Memento Pattern |
U u being fostered fostered |
U u being fostered fostered |
|
Observer model Observer Pattern |
U u u do do |
U u u u u |
|
The state pattern State Pattern |
U u u do do |
U u u do do |
|
The strategy pattern Strategy Pattern |
U do things being fostered fostered |
U u u u do |
|
Template method pattern Template Method Pattern |
U u being fostered fostered |
U u u do do |
|
Visitor pattern Visitor Pattern |
U u u u do |
U do things being fostered fostered |
According to the picture, it can be divided into three types: Creational, Structural and Behavioral. Next, we will explain them in the order of the table schema name. It doesn’t matter how hard it is or how often I use it, because I have to learn both.
Update: 1. What is design mode 2. Singleton mode 3