The structure mode, as its name implies, discusses the structure of classes and objects. It uses an Inheritance Mechanism to combine interfaces or implementations (class structure mode ),
Or you can combine some objects to implement new functions (object structure mode ).
There are seven common structural modes:
- Adapter Mode
- Composite Combination Mode
- Facade appearance Mode
- Decorator decoration Mode
- Bridge Mode
- Flyweight meta Mode
- Proxy mode.
First, let's take a look at the seven modes:
Adapter Mode
Solution: The interface required by the new environment is not met by the existing object. In this case, we can add an adapter to the existing object.
To adapt to the new application environment.
Example: notebook power adapter
Composite Combination Mode
Solved problems:
Solve the decoupling between customer programs and complex object containers. A class of objects with "Container characteristics" -- that is, they act as objects and are containers of other objects, by inheriting the unified interface, we can regard the container object and its sub-objects as the same class object to reduce
Complexity of object usage.
Example: company branch management
Facade appearance Mode
Solved problems:
The simplified interface separates the call of the client program to the child object from the change of the child object.
Example: 10086 Query
Decorator decoration Mode
Solved problems:
The object extension function is implemented on the premise of a stable interface, mainly to solve the problem of expanding the number of sub-objects caused by the extension of a large number of functions for the object through inheritance.
For example, a painting can be attached directly to a wall, or a frame and glass can be added before being mounted to a wall.
Bridge Mode
Solved problems:
Separation interface (abstraction) and its implementation. When a type has two or more changes, the change is isolated by inheriting the interface to reduce the amount of code modified due to the change.
Example: electric switch
Flyweight meta Mode
The solution is to solve the problem that the system memory overhead is too large due to the large number of identical objects.
Example: design different types of websites at the same time.
Proxy Mode
Solution: Solve the Problem of directly accessing some objects.
Example: intermediary companies