Recently, I’m not very busy. I turned over the design mode again and made a special record here. This series of feature articles will be updated from time to time.
Design pattern is a summary of code design experience that is repeatedly used, known by most people, classified and catalogued.
The purpose of using design patterns is to reuse the code, make the code easier to be understood by others and ensure the reliability of the code.
There is no doubt that design patterns win more for themselves, others and the system; The design pattern makes the coding truly engineering; Design pattern is the cornerstone of software engineering, just like the structure of a building.
Design patterns are divided into three types, a total of 23.
Ⅰ. Create mode
1.1 Singleton pattern
Ensure that a class has only one instance and provide a global access point to access it. (singleton mode is one of the simplest design modes)
1.2 Abstract factory pattern
Provides an interface to create a series of related or interdependent objects without specifying their specific classes.
1.3 builder pattern
Separate the construction of a complex object from its representation, so that the same construction process can create different representations.
1.4 factory pattern
Define an interface for creating objects and let subclasses decide which class to instantiate. Factory method delays the instantiation of a class to its subclasses.
1.5 prototype pattern
Specify the type of object to be created with the prototype instance, and create a new object by copying the prototype.
Ⅱ. Structural mode
2.1 adapter pattern
Convert the interface of a class into another interface that the customer wants. The adapter pattern allows classes that cannot work together because of interface incompatibility to work together.
2.2 bridge pattern
Separate the abstract part from its implementation part so that they can change independently.
2.3 Decorator Pattern
Dynamically add some additional responsibilities to an object. In terms of extension function, it is more flexible than generating subclasses.
2.4 composite pattern
Combine objects into a tree structure to represent a “part whole” hierarchy. It enables customers to use single objects and composite objects consistently.
2.5 FA ç ade pattern
Provide a consistent interface for a set of interfaces in the subsystem. The facade pattern defines a high-level interface, which makes the subsystem easier to use.
2.6 flyweight pattern
Use a large number of fine-grained object sharing technologies effectively.
2.7} proxy pattern
Provide a proxy for other objects to control access to this object.
Ⅲ. Structural mode
3.1 template method pattern
Define the skeleton of the algorithm in an operation and delay some steps to subclasses. Template method enables subclasses to redefine some specific steps of an algorithm without changing the structure of the algorithm.
3.2 command pattern
Encapsulate a request as an object, so that you can parameterize the customer with different requests; Queue or log requests, and support cancellable operations.
3.3 iterator pattern
Provides a method to sequentially access the elements of an aggregate object without exposing the internal representation of the object.
3.4 observer pattern
Define a one to many dependency between objects so that when the state of an object changes, all objects that depend on it are notified and refreshed automatically.
3.5 mediator pattern
A mediation object is used to encapsulate a series of object interactions. Mediators make objects do not need to explicitly refer to each other, so that they are loosely coupled, and the interaction between them can be changed independently.
3.6 memo pattern
Without breaking the encapsulation, capture the internal state of an object and save the state outside the object. This will restore the object to the saved state later.
3.7 Interpreter pattern
Given a language, define a representation of its grammar and define an interpreter that uses the representation to interpret sentences in the language.
3.8 state pattern
Allows an object to change its behavior when its internal state changes. Object appears to have modified the class to which it belongs.
3.9 strategy pattern
Define a series of algorithms, encapsulate them one by one, and make them interchangeable. This mode makes the changes of the algorithm independent of the customers who use it.
3.10 chain of responsibility
In order to decouple the sender and receiver of the request, multiple objects have the opportunity to process the request. Connect these objects into a chain and pass the request along the chain until an object processes it.
3.11 visitor pattern
Represents an operation that acts on elements in an object structure. It allows you to define new operations on elements without changing their classes.