Abstract
- What are design patterns and their advantages
- It is divided according to purpose and scope of action
- Twenty-three design patterns are introduced
Introduction to the
At present, there are 23 design patterns in software engineering, which can be classified according to their purpose and scope of action. The essence of design pattern is the practical application of object-oriented design principles, and it is a full understanding of the encapsulation, inheritance and polymorphism of classes as well as the associative and combinative relations between classes.
advantages
- Thinking ability, programming ability, design ability
- Design standardization, code compilation engineering
- Ensure code repeatability, readability, reliability, flexibility, and maintainability
classification
- Purpose divided
- Creation pattern
- Separate object creation from usage
- Five creation modes
- The singleton
- The prototype
- The factory method
- The abstract factory
- The builders
- Structural mode
- Describe how classes or objects are grouped into a larger structure in some layout
- Seven structural modes
- The agent
- The adapter
- The bridge
- decoration
- appearance
- The flyweight
- combination
- Behavioral pattern
- Describes classes or objects that work together to accomplish tasks that a single object cannot accomplish, and the division of responsibilities
- Eleven behavioral patterns
- Template method
- strategy
- The command
- cor
- state
- The observer
- broker
- The iterator
- The visitor
- The memo
- The interpreter
- Creation pattern
- Scope division
- Class model
- The relationships between classes and subclasses, which are established by inheritance, are static and are stabilized at compile time
- Four-category model
- (Class) adapter
- Template method
- The interpreter
- The factory method
- Object pattern
- Used to deal with relationships between objects, which can be implemented by composition or aggregation, that can change dynamically at run time
- Nineteen object patterns
- Class model
Detailed introduction
- 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.
- Prototype pattern: Use an object as a Prototype and clone it to create new instances similar to the Prototype.
- Factory Method pattern: Defines an interface for creating products, and subclasses decide what products to produce.
- AbstractFactory pattern: provides an interface to create a family of products, each subclass of which can produce a series of related products.
- Builder pattern: Decompose a complex object into relatively simple parts, then create them separately according to different needs, and finally build the complex object.
- 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.
- Adapter pattern: Converts the interface of one class into another interface that the customer expects, making classes that would otherwise not work together due to interface incompatibility work together.
- Bridge pattern: Separate the abstraction from the implementation so that they can vary 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.
- Decorator pattern: Dynamically add some responsibility to an object, that is, add additional functionality.
- Facade pattern: Provides a consistent interface to multiple complex subsystems, making them more accessible.
- Flyweight pattern: Sharing techniques are used to efficiently support reuse of large numbers of fine-grained objects.
- Composite pattern: Groups objects into a tree-like hierarchy, giving users consistent access to individual and Composite objects.
- TemplateMethod pattern: define the skeleton of an algorithm in an operation and defer some steps of the algorithm to subclasses so that subclasses can redefine specific steps of the algorithm without changing the structure of the algorithm.
- Strategy pattern: A series of algorithms are defined and each algorithm is encapsulated so that they are interchangeable and the change of the algorithm does not affect the customers using the algorithm.
- Command pattern: Encapsulates a request as an object, separating the responsibility for making the request from the responsibility for executing the request.
- Chain of Responsibility pattern: Requests are passed from one object in the Chain to the next until the request is responded to. In this way, objects are decoupled.
- State mode: Allows an object to change its behavior when its internal State changes.
- 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.
- 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.
- 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.
- Visitor pattern: Provides multiple access to each element in a collection without changing the collection elements, that is, multiple Visitor objects for each element.
- Memento pattern: Retrieves and saves the internal state of an object so that it can be restored later without breaking encapsulation.
- The Interpreter pattern: Provides the grammar of how to define a language and the method of interpreting language sentences, called the Interpreter.
reference
[1]. Classification and function of 23 design patterns in GoF
[2]. Overview of software design patterns
By Both Savage
This paper links: bothsavage. Making. IO / 2020/12/30 /…
Copyright Notice: All articles on this blog are licensed BY-NC-SA unless otherwise stated. Reprint please indicate the source!