Design Mode Study Notes
Factory method, Abstract Factory
The factory method is to hand over the process of producing a product (new instance) to the factory. When a product is required, it is directly requested from the factory without self-production (many attributes may need to be set when a new instance is created, therefore, the work should be handed over to the factory.) a factory can only produce one type of products;
The abstract factory abstracts the factory. A factory can produce multiple types of products.
Decoration mode, appearance mode, proxy mode, bridging mode, mediation Mode
The decoration mode needs to pass the decorated instance to the decorator;
The appearance mode is to unify things that are always done together into a function. The function calls specific things to be done, similar to abstracting things;
In proxy mode, the agent is solely responsible for proxy;
The bridge mode is to introduce a bridge to achieve a certain purpose. For example, when we send a parcel to the express delivery company, we also tell the express delivery company where to send it, the express delivery company here is equivalent to bridge without worrying about how it is delivered. (JDBC)
The mediation mode is the resources (class instances) held by the Mediator. When we need these resources (some methods of the instance need to be called) apply to the intermediary (call the intermediary's method ).
Single-Column mode and metadata Mode
The single-column Mode means that each client calls the same instance;
The metadata mode initializes a certain number of instances in advance. One instance can only be used by one client at the same time. After the call is completed, other clients can use the instance again, that is to say, each instance can be reused. (Connection pool)
Template Method
Polymorphism implemented by inheritance.
Observer Mode
Implement callback through interfaces.
Responsibility Chain Model
Instance a1 of type A can hold another instance a2 of type A. When A method () of Type A1. method () is called, if a2 exists, call a2.method. (Interceptor)
Status Mode
Different States (such as the value of an attribute variable) indicate different behaviors (the results obtained when a function is called or the execution process is different ).
Visitor Mode
Suitable for systems with relatively stable data structures but easily changed algorithms, and vice versa.
Interpreter Mode
Give the interpreter Expression a Context, and the Expression obtains the corresponding value from the Context for calculation (interpret the Context ).