The role of 23 design patterns

Creation type:
Abstract Factory: Provides an interface that can create a series of related or interdependent objects without specifying their specific classes.

Builder mode (Builder): Separate the representation of a complex class from its construction, so that the same construction process can get different representations.

Factory Method: Define an interface for creating objects, but the subclass determines which class needs to be instantiated. The factory method delays the instantiation of subclasses.

Prototype mode (Prototype): Use the prototype instance to specify the type of object to be created, and create a new object by copying the prototype.

Singleton mode (Singleton): Ensure that a class has only one instance, and provide a global access point to access it.

Structural type:
Adapter mode (Adapter): Convert the interface of a class into another interface that the user wants. It enables originally incompatible interfaces to work together.

Bridge mode (Bridge): Separate the abstract part of the class from its realization part, so that they can be changed independently.

Composite mode (Composite): Combine objects into a tree structure to represent a "whole-part" hierarchical structure, so that users have consistency in the use of single objects and combined objects.

Decorator: dynamically add some extra responsibilities to an object. It provides a flexible alternative to extending functionality with subclasses, which is more flexible than deriving a subclass.

Facade: Define a high-level interface to provide a consistent appearance for a group of interfaces in the subsystem, thus simplifying the use of the subsystem.

Flyweight: Provides an effective method to support the sharing of a large number of fine-grained objects.

Proxy mode (Proxy): Provide a proxy for other objects to control access to this object.

Behavioral:
Chain of Responsibility (Chain of Responsibility): By giving multiple objects the opportunity to process the request, it reduces the coupling between the sender and receiver of the request. Link the receiving 14. Objects, and pass the request in the chain until an object handles the request.

Command mode (Command): Encapsulate a request as an object, so that different requests can be parameterized to customers, queue requests or record request logs, and support reversible operations.

Interpreter mode (Interpreter): Given a language, define its grammatical representation, and define an interpreter, which is used to interpret sentences in the language according to the grammatical representation.

Iterator mode (Iterator): Provides a way to sequentially access each element in an aggregate object without exposing the internal representation of the object.

Mediator mode (Mediator): Use a mediator object to encapsulate a series of object interactions. It makes the objects do not need to call each other explicitly, so as to achieve low coupling and independently change the interaction between objects.

Memento mode (Memento) captures the internal state of an object without destroying the encapsulation, and saves this state outside the object, so that the object can be restored to the original state in the future.

Observer mode (Observer): defines a one-to-many dependency relationship between objects. When an object's state changes, all objects that depend on it are notified and automatically updated.

State: Allows an object to change its behavior when its internal state changes.

Strategy mode (Strategy): Define a series of algorithms, encapsulate them one by one, and make them interchangeable, so that the algorithm can change independently of the users who use it.

Template Method: Define the algorithm skeleton in an operation, and delay some steps to the subclass, so that the subclass can redefine some specific steps of the algorithm without changing the structure of an algorithm.

Visitor mode (Visitor): Represents an operation that acts on each element in a certain object structure, so that new operations that act on these elements are defined without changing the class of each element

Guess you like

Origin blog.csdn.net/weixin_43244265/article/details/108473416