Structural patterns describe how to combine classes or objects together to form a larger structure, just like building blocks. Complex and more powerful structures can be formed through the combination of simple blocks.

Structural patterns can be divided into class structural patterns and object structural patterns:

  • The class-structured pattern is concerned with the composition of classes and uses inheritance mechanism to organize interfaces and classes, that is, multiple classes can be combined into a larger system. In class-structured pattern, only inheritance and implementation relations generally exist.
  • The object structural pattern is concerned with the composition of classes and objects, combining objects by composition or aggregation, that is, defining an instance object of another class in one class through association relationships, and then calling its methods through that object. According to the principle of composite reuse, association is used instead of inheritance in the system, so most structural patterns are object structural patterns.

Because the coupling degree of combinatorial or aggregative relation is lower than that of inheritance relation and meets the “composite reuse principle”, object structural pattern has more flexibility than class structural pattern.

Structural modes are divided into the following 7 types:

Adapter mode: Converts one class’s interface into another interface that customers want to buy, allowing classes to work together that otherwise wouldn’t work together due to interface incompatibility. Lent Bridge: Separates abstraction from implementation so that they can change independently. It is realized by using combinatorial relation instead of inheritance relation, thus reducing the coupling degree between abstraction and implementation of these two variable dimensions. Queue composition: Groups objects into a tree-like hierarchy, giving users consistent access to both individual and Composite objects. Decorator mode: You dynamically add some responsibility to an object, adding extra functionality to it. The Facade pattern provides a consistent interface to multiple complex subsystems, making them easier to access. The Flyweight model uses sharing technology to effectively support the reuse of large numbers of fine-grained objects. The Proxy mode, which acts as a Proxy for an object, controls access to the object. That is, a client indirectly accesses an object through a proxy to restrict, enhance, or modify some of its features.

All the above 7 structural patterns belong to the object structural pattern except the adapter pattern which is divided into class structural pattern and object structural pattern.