Structural Patterns focuses on how to organize small classes or objects into a large structure. Structural patterns can be divided into structural class patterns (structure mode) and structural object patterns (Structure object mode ), structural class patterns organizes some interfaces and their implementations with some Object-oriented Inheritance and encapsulation properties, so that the external calls of interfaces and the internal implementations of interfaces are independent; structural object patterns describes how to combine some small objects to implement some new functional structures. In this mode, the combination of these objects becomes flexible, you can even decide or modify the combination mode at runtime.
Structural Patterns consists of the following seven modes: adapter pattern, Bridge pattern, composite pattern, and decorator pattern ), facade Pattern, flyweight pattern, and proxy pattern ).
Adapter pattern:
Adapter pattern converts some class interfaces into the interfaces that the user expects, so that some incompatible classes on the interfaces can coordinate with each other.
During the development process, you may encounter a situation where a function may require a lot of time and effort (or even not implemented by yourself) if it is implemented by yourself ), there are ready-made tools or libraries available on the Internet. If you use the tool kit to implement this function, you can certainly get twice the result with half the effort. The toolkit is developed to facilitate code reuse by developers in the future, but sometimes it cannot be reused directly, because the Toolkit only provides one (or a few) form of interfaces, the interface forms required for different development are almost different, and the interfaces provided by the Toolkit cannot all be compatible with the interface forms required by various development. There are two ways to solve this problem: 1. Modify the Toolkit interface. 2. Use adapter pattern to convert the Toolkit interface (not to be modified) into the desired form. Note the following points when using the first method: 1. it is normal that the Toolkit interface is not compatible with the Interface format used. The toolkit is common instead of applicable to a specific development, therefore, modifications are also made using the Toolkit in specific development. 2. If you want to change the interface form of the Toolkit, you also need to know the source code of the toolkit. 3. Changes to the toolkit may require a lot of work and may cause errors. Therefore, the interface form of the toolkit is usually not modified directly, but the incompatibility between these interfaces is converted into compatibility using the adapter.
(To be continued ......)
Design Pattern ---- Structural Patterns