Adapter mode, decorator mode, and proxy mode belong to the structural mode in the design mode. The structural design mode solves the coupling problem between modules from the structure of the program.

Intent : Convert the interface of one class to another interface that the client wants. The Adapter mode allows classes that would otherwise not work together due to incompatible interfaces to work together.
The Adapter mode focuses on transforming existing interfaces through class inheritance or object combination. The class adapter adopts the "multi-inheritance" implementation method, which brings bad coupling, so it is generally not recommended. The object adapter adopts the "object combination" method, which is more in line with the loose coupling spirit.
For example, a laptop power adapter can convert 220v into a voltage suitable for notebook use.
Applicability :
You want to use an existing class, and its interface does not meet your needs.
You want to create a class that can be reused, which can work with other unrelated classes or unforeseen classes (that is, classes that might not be compatible with those interfaces).
(Applies to object Adapter only) You want to use some subclasses that already exist, but it is not possible to subclass each to match their interfaces. The object adapter can adapt its parent class interface.
Proxy mode
Intent : Provides a proxy for other objects to control access to this object, solving the problem of direct access to certain objects.
For example: the lawyer itself is an agent of our rights!
Applicability : Use Proxy mode when you need to replace simple pointers with more general and complex object pointers.
Here are some common situations where you can use Proxy mode:
Remote Proxy provides a local representation of an object in different address spaces.
Virtual Proxy creates objects that are expensive when needed.
The ProtecTIon Proxy controls access to the original object. The protection agent is used when the object should have different access rights.
The Smart Reference replaces a simple pointer that performs some additional operations when accessing an object. Its typical uses include:
A reference to a reference to the actual object so that when the object has no references, it can be automatically released (also known as SmartPointers).
When a persistent object is referenced for the first time, it is loaded into memory.
Before accessing an actual object, check to see if it has been locked to ensure that other objects cannot change it.
Decorative pattern
Intent : Dynamically add some additional responsibilities to an object. In terms of adding functionality, the Decorator mode is more flexible than generating subclasses. The Decorator pattern uses object composition rather than inheritance to achieve the ability to dynamically extend object functionality at runtime, and can extend multiple functions as needed, avoiding the "poor flexibility" and "multiple subclasses" used by inheritance alone. Derived problems." At the same time, it fits well with the principle of “preferring the use of object combinations rather than inheritance†and “open-closed†principles in object-oriented design principles.
For example: a painting can be hung directly to the wall, or it can be attached to the wall and then attached to the wall.
Applicability :
Add responsibilities to individual objects in a dynamic, transparent manner without affecting other objects.
Handle responsibilities that can be undone.
When you can't use the method of generating subclasses to expand. In one case, there may be a large number of independent extensions, and a large number of subclasses will be generated to support each combination, causing the number of subclasses to explode. Another situation may be because the class definition is hidden, or the class definition cannot be used to generate subclasses.
The difference between adapter mode, decorator mode, and proxy mode
The adapter is characterized by compatibility. From the characteristics of the code, the adaptation class has the same interface as the original class and holds the new target object.
Just like a three-hole to 2-hole adapter, it has a three-hole plug that plugs into a three-hole socket, and a two-hole socket that can be plugged into a 2-hole plug.
The adapter mode is based on the modification of the original 3 holes.
When using the adapter mode, we must hold the original object, the adaptation object, and the target object. . . .
The decorator pattern is characterized by enhancement. Its characteristic is that the decorated class and all the decorative classes must implement the same interface, and must hold the decorated object, which can be infinitely decorated.
The proxy mode is characterized by isolation, isolation of the relationship between the calling class and the called class, and calling through a proxy class.
In general, the following three sentences:
1 Adapter mode is to convert a class (a) into another class (b) in some way.
2 The decoration mode is to add some new functions to another class (b) based on an original class (a).
3 Proxy mode is to convert a class (a) into a concrete operation class (b).
to sum upSimply convert the original interface to another interface that the client wants, which is the adapter mode. The conversion is nothing more than 1. inherit the original class or implement the original interface 2. Hold the object of the original interface, and then implement the target interface. Then the first is the adaptation of the class, and the second is the adaptation of the object.
The biggest difference between the proxy mode and the adapter mode is that the proxy mode implements the same interface as the original object, and the adapter class matches the new interface. To put it bluntly, a new interface is implemented.
In decorator mode, there must be a class of decorated classes and decorations. The proxy mode must be this object itself, and does not need to be passed in from outside. The decoration mode must be passed in from the outside, and there can be no order, and the order can be randomly changed according to the actual needs of the code. From the point of view of usage, the proxy mode focuses on the isolation restriction, so that the external can not access your actual call object, such as permission control, the decoration mode focuses on the expansion of functions, and achieve more functions under the same method.
KNM1L Series Moulded Case Circuit Breaker
KNM1L series Moulded Case Circuit Breaker is MCCB , How to select good Molded Case Circuit Breaker suppliers? Korlen electric is your first choice. All moulded Case Circuit Breakers pass the CE.CB.SEMKO.SIRIM etc. Certificates.
Moulded Case Circuit Breaker /MCCB can be used to distribute electric power and protect power equipment against overload and short-current, and can change the circuit and start motor infrequently. The application of Moulded Case Circuit Breaker /MCCB is industrial.
Korlen electric also provide Miniature Circuit Breaker /MCB. Residual Current Circuit Breaker /RCCB. RCBO. Led light and so on .
KNM1L series Molded Case Circuit Breaker,KNM1L series Small Size Molded Case Circuit Breaker,KNM1L series Electrical Molded Case Circuit Breaker,KNM1L series Automatic Molded Case Circuit Breaker
Wenzhou Korlen Electric Appliances Co., Ltd. , https://www.zjthermalrelay.com