1. Singleton mode
Ensure that a class has only one instance, instantiates itself and provides this instance to the whole system.
2. Factory method
Define an interface for creating objects and let subclasses decide which class to instantiate. Factory methods delay instantiation of a class to its subclasses.
3. Abstract factory pattern
Provide an interface for creating a set of related or interdependent objects without specifying their specific classes.
4. Template method pattern
Define the framework of an algorithm in operation, and delay some steps to subclasses. The subclass can redefine some specific steps of the algorithm without changing the structure of the algorithm.
5. Builder mode
Separate the construction of a complex object from its representation, so that the same construction process can create different representations.
6. Agent mode
Provide a proxy for other objects to control access to this object.
7. Prototype mode
Use prototype instances to specify the types of objects to create, and create new objects by copying these prototypes.
8. Intermediary model
A mediator object is used to encapsulate a series of object interactions. The mediator makes each object interact without display, so that its coupling is loose, and the interaction between them can be changed independently.
9. Command mode
Encapsulating a request into an object allows you to parameterize the client with different requests, queue requests or record request logs, which can provide command revocation and recovery functions.
10. Responsibility chain model
Multiple objects have the opportunity to process the request, thus avoiding the coupling relationship between the sender and receiver of the request. Connect these objects into a chain and pass the request along the chain until an object processes it.
11. Decoration mode
Dynamically add some additional responsibilities to some objects. In terms of adding functions, decoration pattern is more flexible than generating subclasses.
12. Strategy mode
Define a set of algorithms, encapsulate each algorithm, and make them interchangeable.
13. Adapter mode
Replace the interface of a class with another interface expected by the client, so that the two classes that could not work together due to interface mismatch can work together.
14. Iterator mode
It provides a way to access each element in a container object without exposing the internal details of the object.
15. Combination mode
The objects are combined into a tree structure to represent the "part whole" hierarchy, so that users have consistency in the use of single objects and combined objects.
16. Observer mode
Defining objects is a one to many dependency, so that whenever an object changes state, all objects that depend on it will be notified and updated automatically.
17. Facade mode
It is required that the external and internal communication of a subsystem must be carried out through a unified object. Facade mode provides a high-level interface, which makes the subsystem easier to use.
18. Memo mode
Without breaking the encapsulation, capture the internal state of an object and save the state outside the object. This will restore the object to its original saved state later.
19. Visitor mode
Encapsulates some operations that act on each element in a data structure. It can define new operations that act on these elements without changing the data structure.
20. State mode
When an object's internal state changes, it is allowed to change its behavior, and the object looks like it has changed its class.
21. Interpreter mode
Given a language, define a representation of its grammar and define an interpreter that uses the representation to interpret sentences in the language.
22. Enjoy yuan mode
Using shared objects can effectively support a large number of fine-grained objects.
23. Bridge mode
Decouple abstraction from implementation so that both can change independently.
java设计模式 (java design pattern)
最新推荐文章于 2023-02-13 15:03:00 发布