Image example:
-If you encounter mm in the morning, say good morning, or mm in the evening, say good evening; if you encounter mm in a new dress, say that your clothes are so beautiful, and meet mm in a new hairstyle, say your hair looks pretty. Don't ask me the question of "how to say mm has a new hairstyle in the morning". Just use bridge to combine it.
Bridge Mode: Abstraction and implementation are decoupled so that the two can change independently, that is, the strong association between them becomes weak Association, that is, the combination/aggregation relationship is used between the abstraction and implementation of a software system, rather than the inheritance relationship, so that the two can change independently.
Purpose:
Separate the abstract part from its implementation part so that they can all change independently.
UML:
Abstract base class:
1) define action: an abstract class, which is implemented by implementor.
2) implementor: the abstract base class of the implementation class, which defines the basic operations for implementing abastraction, and its derived class implements these interfaces.
Interface functions:
1) implementor: operationimpl: defines the basic operations required to implement the role action. It is implemented by the implementor's derived class, and in the role Action :: the operation function calls this function according to the polymorphism of different pointers.
Resolution:
Bridge is used to decouple representation and implementation. The two can be independent of each other. maintain an implementor class pointer in the role action class. You only need to input different implementor class classes when using different implementation methods.
The implementation method of bridge is actually very similar to Builde. It can be said that it is essentially the same, but the encapsulated things are different. the two implementations have the following commonalities: Abstract A base class, which defines some common behaviors and forms interface functions (programming interfaces rather than implementing them ), the buildepart function in buildier is the operationimpl function in bridge. Second, it aggregates a base class pointer. For example, in builder mode, the director class aggregates a builder base class pointer, in the brige mode, the aggregate action class aggregates the pointer of an implementor base class (aggregation rather than inheritance is preferred, they all encapsulate the use of this class in a function. In bridge, they are encapsulated in the Director: Construct Function, because the process of assembling different parts is consistent, in the bridge mode, it is encapsulated in the invoke Action: operation function. In this function, the corresponding implementor: operationimpl function is called. for the two modes, builder encapsulates different methods of generating components, while bridge encapsulates different implementation methods.
Therefore, if we analyze the implementation of these patterns with some basic object-oriented design principles, we can still see a lot of common points.
Design Pattern _ Bridge