Structural Pattern

Structural patterns describe how objects of a class can be combined together to form a larger structure. Structural patterns describe two different things: classes and instances of classes. Therefore, it can be divided into class structure pattern and object structure pattern.

In GoF design patterns, structural patterns are:

1. Adapter mode Adapter
  The adapter pattern is to convert the interface of a class into another interface that the client wants. The adapter pattern enables classes to work together that would otherwise not work together due to incompatible interfaces.
  Two mature classes need to communicate, but the interfaces are different. Due to the open-closed principle, we cannot modify the interfaces of these two classes, so an adapter is needed to complete the connection process.
2. Bridge mode Bridge
  The bridge pattern separates the abstraction from its implementation so that they can both be changed independently. It supports the open-closed principle and the combination saw and reuse principle very well. The implementation system may be classified from multiple angles, and each classification may change, so separate these multiple angles to allow them to change independently and reduce the coupling between them.
3. Composite mode
  Composition mode combines objects into a tree structure to represent part-whole hierarchies, and composition mode enables users to use individual objects and composite objects consistently.
4. Decoration mode Decorator
The Decorator pattern dynamically adds some additional responsibilities to an object, and is more flexible than subclassing in terms of adding functionality. It can also be said that the decoration mode separates the core responsibilities and decoration functions of complex classes, which not only simplifies complex classes, but also removes the repeated decoration logic in related classes. The decoration pattern does not extend the functionality by inheriting the original class, but it achieves the same purpose and is more flexible than inheritance, so it can be said that the decoration pattern is an alternative to the inheritance relationship.  
5. Facade mode

 The Facade pattern provides an agreed-upon interface for a set of interfaces in a subsystem. The Facade pattern defines a high-level interface that makes the subsystem easier to use.

In the appearance mode, the customer does not understand each specific subsystem, so these subsystems are encapsulated, and only a single and simple interface that the user understands is provided to the outside world. The user can directly use this interface to complete the operation, while You don't need to pay attention to the specific process, and the changes of the subsystem will not affect the user, so the information is concealed.

6. Flyweight

 The Flyweight pattern uses sharing techniques to efficiently support a large number of fine-grained objects. Because it can drastically reduce the number of individual instances through sharing, avoiding the overhead of a large number of very similar classes. .

      The Flyweight pattern is that multiple objects of a class share an object of this class, rather than each re-instantiating their own objects. This achieves the purpose of saving memory.

7. Proxy mode Proxy    
Provide a proxy for other objects, and the proxy object controls the reference to the original object to indirectly control the access to the original object.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324734594&siteId=291194637