First, the creation mode
- Abstract Factory Pattern: Provides an interface for creating a family of related or dependent objects without specifying a specific class.
- Builder pattern: Uses the builder pattern to encapsulate the construction of a product and allows for construction by step. Separating the construction of a complex object from its representation allows the same build process to create different representations.
- Factory mode (factory method pattern): Defines an interface for creating objects, but subclasses decide which class to instantiate. The factory method defers the instantiation of the class to the subclass.
- Prototype mode (prototype pattern): Use prototype mode when creating an instance of a given class is expensive or complex.
- Singleton mode (Singleton pattern): Ensures that a class has only one instance and provides a global access point.
- Multition pattern: Combine two or more patterns in a solution to solve a common or recurring problem.
Second, structural type mode
- Adapter mode (Adapter pattern): Transforms the interface of a class into another interface that the customer expects. Adapters allow classes that are incompatible with the original interface to work together. Object adapters use combinations, and class adapters use multiple inheritance.
- Bridging mode (bridge pattern): Use bridging mode to change the implementation and abstraction independently by placing them in two different class hierarchies.
- Combined mode (composite pattern): Allows you to combine objects into a tree structure to represent a "whole/part" hierarchy. The combination enables the customer to handle individual objects and object combinations in a consistent manner.
- Decorator mode (decorator pattern): to dynamically attach responsibility to an object, the adorner provides a more resilient alternative than inheritance to extend functionality.
- Appearance mode (facade pattern): Provides a unified interface for accessing a group of interfaces in a subsystem. The appearance defines a high-level interface that makes the subsystem easier to use.
- Hengyuan mode (Flyweight pattern): If you want an instance of a class to be used to provide many "virtual instances," Use the fly volume pattern.
- Proxy pattern: Provides an alias or placeholder for another object to control access to the object.
Iii. Behavioral Patterns
- Responsibility chain mode (Chain of responsibility pattern): You can create an object chain for a request through the chain of responsibility model. Each object sequentially examines the request and processes it, or passes it to the next object in the chain.
- Command pattern: The request is closed to objects so that different requests, queues, or logs are used to parameterize other objects. The command mode also supports the revocable operation.
- Interpreter mode (interpreter pattern): Creates an interpreter for the language using the interpreter pattern.
- Iterator pattern (iterator pattern): Provides a way to sequentially access individual elements in an aggregated object without exposing their internal representations.
- Mediator mode (mediator pattern): uses the mediator pattern to centralize the complex communication and control patterns between related objects.
- Memo Mode (Memento pattern): You use Memo mode when you need to return an object to its previous state (for example, if your user requests "undo").
- Observer pattern (Observer pattern): Defines a one-to-many dependency between objects, so that when an object changes state, objects that depend on it are notified and updated automatically.
- State pattern: Allows an object to change its behavior when the internal state changes, and the object looks as if it had changed its class.
- Policy mode (strategy pattern): Defines the algorithm family, respectively closed up, so that they can be replaced with each other, this pattern allows the algorithm to change independently of the customers using the algorithm.
- Template method Pattern: Defines the skeleton of an algorithm in a method, and delays some steps into subclasses. The template method allows subclasses to redefine some of the steps in the algorithm without changing the structure of the algorithm.
- Visitor Mode (visitor pattern): Use the visitor pattern when you want to add new capabilities to a combination of objects, and the encapsulation doesn't matter.
Seven major design principles
- Single RESPONSIBILITY PRINCIPLE: one class is responsible for one responsibility.
- Richter replacement principle "LISKOV SUBSTITUTION PRINCIPLE": Inherited and derived rules.
- Dependency inversion principle "dependence inversion PRINCIPLE": The high-level module should not rely on the lower layer module, both should rely on its abstraction; abstraction should not depend on detail; detail should depend on abstraction. That is, for interface programming, do not program for implementation.
- Interface Isolation principle "INTERFACE segregation PRINCIPLE": Set up a single interface, do not set up a huge bloated interface, as far as possible to refine the interface, the interface of the method as little as possible.
- The Dimitri law "low of DEMETER": Cohesion Poly.
- Open Close PRINCIPLE: A software entity such as classes, modules, and functions should be open to extensions, closed for modifications, and add functionality to the program by adding the implementation class instead of modifying the original code
- Combination/Aggregation multiplexing principle "composition/aggregation reuse Principle (CARP)": Use combinations as much as possible, and use less inherited relationships to achieve the principle of reuse
24 Design Patterns and 7 principles in Java