There are two ways to classify design patterns, namely, according to the purpose of the pattern and according to the scope of the pattern

1. Classification according to purpose

According to what the purpose of the pattern is to accomplish, this pattern can be divided into three types: creation pattern, structural pattern and behavior pattern

  1. The creation pattern describes how objects are created. Its main feature is the separation of object creation and use. GoF provides 5 creation patterns, such as singleton, prototype, factory mode, Abstract factory and Builder.
  2. Structural patterns: Used to describe how a type or object is arranged in a certain way into a larger result. GoF provides seven structural patterns: proxy, adapter, bridge, decoration, appearance, share element, composition.
  3. Behavioral pattern: Describes how classes or objects work together to accomplish tasks that a single object could not accomplish alone, and how responsibilities are assigned. Template methods are provided in GoF:Policy, naming, chain of responsibility, state, observer, mediator, iterator, visitor, memo, interpreterAnd 11 behavioral patterns.


2. Classification according to scope of action

  1. Class pattern: Used to deal with relationships between classes and subclasses, which are established by inheritance and are static and determined at compile time. Factory methods, (class) adapters, template methods, and interpreters in GoF belong to this pattern.
  2. Object pattern: Used to deal with relationships between objects, which can be implemented through composition and aggregation, that can change at run time and are more dynamic. All but four of the above are object modes in GoF.


Classification of 23 design patterns




3. GoF features 23 design modes

  1. Singleton pattern: Only one instance of a class can be generated. This class provides a global access point for external access to the instance. The extension is the finite-multiple pattern.
  2. Prototype pattern: Clone an object as a Prototype by copying it to create a new instance similar to the Prototype.
  3. Factory Method: Defines an interface for creating products, and subclasses decide what products to produce.
  4. Abstract Factory: Provides an interface to create a family of products, each subclass of which can generate a series of related products.
  5. Builder pattern: Decompose a complex object into relatively simple parts, then create them separately according to different needs, and finally create the complex object.
  6. Proxy mode: Provides a Proxy for an object to control access to that object. That is, a client indirectly accesses an object through a proxy to restrict, enhance, or modify some of its features.
  7. Adapter pattern: Converts the interface of one class into another interface that the customer expects, making classes that cannot work together due to interface incompatibility work together.
  8. Bridge pattern: Separate the abstraction from the implementation so that they can be transformed independently. It is realized by using combinatorial relation instead of inheritance relation, thus reducing the coupling degree of abstraction and realization of these two variable dimensions.
  9. Decorator pattern: Dynamically add some responsibility to an object, that is, add additional functionality.
  10. Facade pattern: Provides a consistent interface to multiple complex subsystems, making them more accessible.
  11. Flyweight pattern: Sharing techniques are used to efficiently support reuse of large numbers of fine-grained objects.
  12. Composite pattern: Groups objects into a tree-like hierarchy, giving users consistent access to individual and Composite objects.
  13. Pattern method pattern: Define the skeleton of an algorithm in an operation and defer some steps of the algorithm to a subclass so that the subclass can redefine specific steps of the algorithm without changing the structure of the algorithm.
  14. Strategy pattern: A series of algorithms are defined, and each algorithm is encapsulated so that they can be replaced with each other, and algorithm changes do not affect the customers using the algorithm.
  15. Command pattern: Encapsulates a request as an object, separating the responsibility for making the request from the responsibility for executing the request.
  16. Chain of Responsibility pattern: Pass requests from one object in the Chain to the next until the request is responded to. In this way, objects are decoupled.
  17. State mode: Allows an object to change its behavior when its internal State changes.
  18. The Observer pattern: There is a one-to-many relationship between objects. When one object changes, the change is notified to the other objects, thereby affecting the behavior of the other objects.
  19. Mediator mode: Define an intermediary object to simplify the interaction between the original objects, reduce the degree of coupling between the objects in the system, so that the original objects do not need to understand each other.
  20. The Iterator pattern: Provides a way to access a series of data in an aggregate object sequentially without exposing the internal representation of the aggregate object.
  21. Visitor pattern: Provides multiple access to each element in a collection without changing the collection elements, that is, multiple Visitor objects for each element.
  22. Memento pattern: Retrieves and saves the internal state of an object so that it can be restored later without breaking encapsulation.
  23. The Interpreter pattern: Provides the grammar of how to define a language and the method of interpreting language sentences, called the Interpreter.


Source: GoF’s classification and functionality of 23 design patterns