Design mode understanding Adams Wang
Object-oriented refers to the use of discrete objects to build software systems; design patterns utilize the inheritance, combination, and agent of the object, consider problems at higher OOP high levels. In particular, the agent uses the agent, such as the state, the creation of the object, the application platform, etc., which ensures the reuse and design of the source code. In fact, it can be understood that it is an extension of the virtual function and polymorphism concept in OOP. That is, the virtual function and polymorphism implementation in OOP is the method, object behavior, and the design mode has a polymorphism of creation, structure, and high levels.
Creation Pattern
When the system evolves into a combination of objects, the creative mode has brought more flexibility when aggregation.
Abstract Factory: Abstract factory is to create a target family. It ensures consistency of a family of objects that is created, and flexibility in the target family, can be applied in cross-platform design.
Prototype: A responsibility agent generated by the object to its own mode. It is different from the copy functions in C , and C does not support the polymorphism of the copy function, that is, when the object uses a pointer to the base class, it cannot be copied according to the subclass, resulting in cutting. Prototype gives a lot of applications in Java.
Builder: The side focus is in the process of object creation, avoiding a lot of hard code in CODE. When the created object structure changes. Avoid modifications to spread a large number of new statements in the program.
Factory Method: A solution when generating an object is uncertain. In fact, in C and Java, it is relatively easy to understand the virtual function, that is, when a method is uncertain, the virtual function is used to declare, and the specific implementation is given to the subclass. Factory Method It implements the polymorphism when the object is created.
Singleton is similar to a technique, using OOP technology, enforcement of limited and quantitative objects.
Comparison: Factory Method implements the created polymorphism; Prototype implements a copy of the polymorphism; Builder implements the polymorphism of the object creation process.
Structural Pattern
Structural mode focuses on how to make a larger structure of classes and objects, which brings flexibility when the object is combined.
Composite: Suitable for expressing the overall-part relationship, you can ignore the difference between a single object and the synthesis object. It actually uses a tree structure.
Decorator: Unlike inheritance, a polymorphism is achieved in a proxy, which can avoid derivation of a large number of subclasses. It is suitable for the structure of chain and tree.
Proxy: The structure is very similar to Decorator, and their side focus is different, one is the behavior of modifying the object, and another control is accessed.
Bridge: The permanent binding between abstraction and implementation can be understood as designed based on existing components, and existing design may change. It often uses Abstract Factory for cross-platform design.
Façade: Used to provide a unified interface to the subsystem.
Behavioral Pattern
Behavioral mode involves responsibilities and assignments between algorithms and objects. Behavior mode describes the contact information between communication, control methods, and objects.
CHAIN of Responsibility: For the chain structure, transfer the responsibilities along the chain, do not show the assurance of the specified responsibility, and the object of responsibility is achieved by the object.
Command: Pack a task into an object, can be used with Memento for Undo.
Iterator: A large number of applications in the algorithm, encapsulating traversal operations.
Mediator: The introduction of the intermediary object becomes the structure of the mesh-centered star structure, thereby ensuring the stability of the object structure, that is, the modification of the pointers in a large number of classes due to the introduction of the new object. Observer: Deformation of the classic MVC mode, similar to the structure of Mediator, in the subject level is a star structure. They all become a star structure, but the side focus is different.
State: The OO implementation of the classic method state machine can be applied to the controlled intensive system.
Strategy: Pack the algorithm. Suitable for software that is efficient to improve the efficiency in software.
Visitor: The actual matrix structure in the subject level is similar to Abstract Factory. They provide flexibility and consistency for a dimension of the matrix with an agent of the object.