Singleton design pattern
This type of design pattern is a creation pattern, which provides the best way to create objects. This pattern involves a single class that is responsible for creating its own objects while ensuring that only a single object is created. This class provides a way to access its unique object, which can be accessed directly without instantiating the object of the class.
Factory model
Simple factory mode
The process of creating an object is encapsulated, and the object can be directly obtained through parameters. Separate the creation of objects from the business logic layer, so that the modification of customer code will be avoided in the future. If you want to implement a new product to directly modify the factory class without modifying it in the original code, this reduces the possibility of customer code modification and makes it easier to expand.
Factory method mode
Define an interface for creating objects, letting the subclass decide which product class object to instantiate. The factory method delays the instantiation of a product class to a subclass of its factory.
Abstract factory pattern
It is a schema structure that provides an interface for accessing classes to create a set of related or interdependent objects, and accessing classes can obtain products of different levels of the same family without specifying the specific class of the desired product.
The abstract factory model is an upgraded version of the factory method model. The factory method model only produces products of one level, while the abstract factory model can produce products of multiple levels.
Prototype mode
Use an instance that has been created as the prototype and create a new object that is the same as the prototype object by copying the prototype object.
Builder Mode
Separate the construction and representation of a complex object.Java trainingThis allows the same build process to create different representations. The structure of the component (the Buildler is responsible) and assembly (the Director is responsible). This allows complex objects to be constructed. This pattern is suitable for situations where the construction process of an object is complicated.
Agent Mode
For some reason, an object needs to be provided with a proxy to control access to that object. At this time, the access object is not suitable or cannot directly refer to the target object, and the proxy object serves as an intermediary between the access object and the target object. Agents in Java are divided into static agents and dynamic agents according to the different timings of generation of agent classes. The static proxy proxy class is generated during the compilation period, while the dynamic proxy proxy class is generated dynamically during Java runtime. Dynamic proxy includes two types: JDK proxy and CGLib proxy.
Adapter mode
Convert an interface of one class into another interface that the client wants so that classes that were originally unable to work together due to incompatibility of the interface can work together.
Decorator mode
Without changing the existing object structure, dynamically add some responsibilities (i.e., to increase its extra-face function) to the object.
Bridge mode
Separate abstractions from implementations so that they can be changed independently. It is implemented by combining relationships instead of inheritance relationships, thereby reducing the coupling between abstraction and implementation of these two variable dimensions.
Appearance mode
Also known as facade mode, it is a pattern that makes these subsystems more accessible by providing a consistent interface to multiple complex subsystems. This mode has a unified interface to the outside world, and external applications do not need to care about the specific details of the internal subsystem, which will greatly reduce the complexity of the application and improve the maintainability of the program. The Facade mode is a typical application of the "Dimit's Law".
Combination mode
Also known as partial overall pattern, it is used to treat a set of similar objects as a single object. The combination pattern combines objects based on a tree structure and is used to represent parts and overall levels. This type of design pattern belongs to the structural pattern, which creates a tree structure of object groups.
Enjoy the Yuan mode
Use sharing technology to effectively support the reuse of a large number of fine social objects. It greatly reduces the number of objects that need to be created by sharing existing objects and avoids the overhead of a large number of similar objects, thereby improving the utilization of system resources.
Template method pattern
In the object-oriented design process, programmers often encounter this situation: when designing a system, they know the key steps required by the algorithm and determine the execution order of these steps, but the specific implementation of some steps is still unknown, or the implementation of some steps is related to the specific environment. Define an algorithm skeleton in an operation, and delay some steps of the algorithm to a subclass so that the subclass can redefine certain specific steps of the algorithm without changing the structure of the algorithm.
Policy Mode
This pattern defines a series of algorithms and encapsulates each algorithm so that they can be replaced by each other, and changes in algorithms do not affect customers using the algorithm. The policy pattern belongs to the object behavior pattern. It encapsulates the algorithm, divides the responsibility of using the algorithm and the implementation of the algorithm, and delegates it to different objects to manage these algorithms.
Command Mode
Encapsulate a request into an object, separating the responsibility for making the request from the responsibility for executing the request. In this way, the two questions are communicated through command objects, which facilitates storage, transmission, invocation, addition and management of command objects.
Responsibility Chain Model
Also known as the chain of responsibility mode, in order to avoid coupling the request sender with multiple request handlers, all request handlers are connected into a chain through the previous object remembering the reference of its next object. When a request occurs, the request can be passed along the chain until an object processes it.
Status Mode
For stateful objects, complex "judgment logic" is extracted into different state objects, allowing the state object to change its behavior when its internal state changes.
Observer mode
Also known as the publish-subscribe (Publish/Subscribe) pattern, it defines a one-to-many dependency, allowing multiple observer objects to listen to a topic object at the same time. When this subject object changes state, it notifies all observer objects, allowing them to automatically update themselves.
Intermediary model
Also known as mediation mode, it defines a mediation role to encapsulate the interaction between a series of objects, loosen the coupling between the original objects, and can independently change the interaction between them.
Iterator mode
Provides an object to access a series of data in an aggregate object sequentially without exposing the internal representation of the aggregate object.
Visitor Mode
Encapsulate some operations acting on each element in a certain data structure, and it can define new operations acting on these elements without changing this data structure.
Memo mode
Also known as snapshot mode, without destroying encapsulation, captures the internal state of an object and saves this state outside the object so that the object can be restored to its original saved state when needed.
Deselector mode
Given a language, define its grammatical representation, and define an interpreter that uses the identifier to interpret sentences in the language.