Design Patterns | ||||
---|---|---|---|---|
Creation type | Structure type | Behavioral | ||
Scope of application | Applied to the class | Factory Method | Adapter | Interpreter Template Method |
Applied to the object | Abstract Factory Builder Prototype Singleton |
Adapter Bridge Composite Decorator Facade Flyweight Proxy |
Chain of Responsibility Command Iterator Mediator Observer State Strategy Visitor |
Note: Mantra
- Creation type: work order extraction original construction
- Structural type: bridge installation suitable for group to enjoy foreign generation
- Behavioural type: repeated fate in the observation and policy of reproach
Creation type | Factory method | Factory Method | Define an interface for creating objects, but the subclass determines which class needs to be instantiated. The factory method causes the instantiation of the subclass to be postponed. |
---|---|---|---|
Singleton mode | Singleton | Ensure that a class has only one instance, and provide a global access point to access it. | |
Abstract factory | Abstract Factory | Provide an interface to create a series of related or interdependent objects without specifying their specific classes. | |
prototype | Portotype | Use the prototype instance to specify the type of object to be created, and create a new object by copying this prototype. | |
builder | Builder | Separate the representation and construction of a complex class, so that the same construction process can get different representations. | |
Structure type | bridging | Bridge | Separate the abstract part and the realization part of the class so that the two can be changed independently. |
Decorator | Decorator | Add some additional responsibilities to an object dynamically. It provides a flexible alternative to extend the functionality with subclasses, making it more flexible to derive a subclass. | |
adapter | Adapter | Converting the interface of a class to another interface that the user hopes to get, it enables the originally incompatible interface to work together. | |
combination | 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. | |
Flyweight | Flyweight | Provide an effective method to support the sharing of a large number of fine-grained objects. | |
Exterior | Facade | Define a high-level interface, a set of interfaces of the sub-system provides a consistent appearance, thus simplifying the use of the sub-system. | |
proxy | Proxy | Provide a proxy for other objects to control access to the entire object. | |
Behavioral | Template method | 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 | Visitor | Represents an operation that acts on each element in an object. This allows the definition of new operations that act on these elements without changing the class of each element. | |
Chain of responsibility | Chain of Responsibility | By giving multiple objects the opportunity to process the request, the coupling between the sender and receiver of the request is reduced. Link the receiving objects and pass the request in the chain until an object handles the request. | |
memorandum | Memento | Under the premise of not destroying the encapsulation, capture the internal state of an object and save this state outside the object, so that the object can be restored to the original state in the future. | |
status | State | Allows an object to change its behavior when its internal state changes. | |
Observer | Observer | Define a one-to-many dependency relationship between objects. When the state of an object changes, all objects that depend on it are notified and updated automatically. | |
Strategy | 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. | |
Intermediary | Mediator | Use an intermediary object to encapsulate a series of object interactions. It makes the objects do not need to call each other explicitly, thereby achieving low coupling, and can independently change the interaction between objects. | |
Iterator | Iterator | Provide a way to sequentially access the elements in an aggregated object without exposing the internal representation of the object. | |
Interpreter | Interpreter | Given a language, define its grammatical representation, and define an interpreter, which is used to interpret sentences in the language based on the grammatical representation. | |
command | Command | 将一个请求封装成一个对象,从而可用不同的请求对客户进行参数化,将请求排队或记录请求日志,支持可撤销的操作。 |