In software engineering, design patterns are used to describe a solution to a problem in a variety of different situations. Object-oriented design patterns typically describe the relationships and interactions in a class or object, which is a problem at the software "design" level. Using design Patterns improves code reusability and reliability, makes code easier to understand, and enables code to be truly engineered.
Generally, the design pattern is divided into three types, a total of 23 kinds:
1. Create pattern
Abstract Factory: Provides a series of interrelated or interdependent interfaces for a product family, and when a series of the product family is needed, the corresponding series can be selected from the abstract project to create a specific engineering class.
Factory mode (Factory method): Defines an interface for creating an object, allowing subclasses to decide which class to instantiate, that is, to defer the instantiation of a class to its subclasses.
Singleton mode (Singleton): Ensures that a class has only one instance and provides a global access point to the instance.
Prototype mode (PROTOTYPE): Specifies the kind of object created with the prototype instance, and creates a new object by copying the prototypes.
Builder mode: Separates the "build" and "presentation" of a complex object so that the same build process can create different representations.
2. Structural mode
Proxy mode: Provides a proxy for other objects to control access to the object.
Adapter mode (Adapter): Converts the interface of a class to another interface representation required by the client, so that those classes that do not match the original interface achieve compatibility effects.
Bridging mode (bridge): separates the abstract and its implementation parts so that they can vary independently.
Combined Mode (Composite): Combines objects into a tree structure to represent a "partial-whole" hierarchy, which allows users to treat individual objects and composite objects uniformly.
Adornment mode (Decorator): is another way to extend functionality beyond class inheritance by dynamically adding some extra functionality to an object.
Appearance mode (facade): Provides a consistent interface for a set of interfaces in a subsystem, and the facade schema defines a high-level interface that makes this subsystem easier to use.
Enjoy meta mode (Flyweight): share technology to effectively support a large number of fine-grained objects.
3. Behavioral Mode
Observer Mode (OBSERVER): Defines a one-to-many dependency between objects so that when an object changes state, other related objects are notified and refreshed automatically.
Policy mode (strategy): Define a series of algorithms, encapsulate them individually, and make them interactive. The strategy mode allows the algorithm to be changed independently when used by the user.
Template method: Constructs a top-level logical framework and delays the details of the logic into specific subclasses. It prepares an abstract class, implements some logic in the form of concrete methods and concrete construction subclasses, and then declares that some abstract methods force subclasses to implement the remaining logic, so that different subclasses can implement these abstract methods in different ways, thus having different implementations of the remaining logic.
Iterator mode (Iterator): Provides a way to sequentially access individual elements of an aggregated object without exposing the internal representation of the modified object.
Visitor Mode (Visitor): Encapsulates some action that is applied to a data structure element. This allows you to implement new operations on these elements without changing the individual element classes. The visitor model is suitable for systems with relatively indeterminate data structures, which frees up the coupling between the structure and the operations acting on the structure, allowing the set of operations to evolve relatively freely.
Command mode: Encapsulates a request as an object so that you can parameterize the customer with different requests, queue requests or log requests, and support actions that can be canceled.
State mode: Allows an object to change its behavior as it changes its internal state. State mode requires the creation of a subclass of the State class for the states that each system may acquire, and the system changes the selected subclass when the state of the system changes.
Interpreter mode (interpreter): Given a language, defines a representation of its grammar, and defines an interpreter that uses that representation to interpret sentences in a language.
Mediator Mode (mediator): Uses a Mediation object to encapsulate a series of object interactions so that the objects do not need to be referenced to each other, thus making them loosely coupled. When the role of some objects changes, the effect of other objects is not immediately affected, ensuring that these effects can vary independently from one another.
Responsibility chain mode (Chain of Responsibility): a coupling between the sender and the recipient of the cancellation request, allowing multiple objects to have the opportunity to process the request. Link the objects together and pass the request along the chain until an object handles it.
Memo Mode (Memento): captures the internal state of an object without compromising encapsulation, and externally saves the state so that the object can later be restored to its saved state.
The design pattern of knowledge point---C + +