Bridging Mode
A. Definition:
Separate the abstract part and its implementation part so that they can change independently.
B. Definition Analysis:
"ChangeAbstractIt is separated from its implementation to allow them to change independently. "Abstract: for example, if we write a GUI Tookit, there is a window class in it. This class represents the window and provides Window Function interfaces such as close, open, resize, and moveTo. the base class interface, which can be understood as an abstract part.
"ChangeAbstractAnd itsImplementationSeparation, so that they can change independently. "the implementation section, the abstract section above is the window class, implementing the window function:
Method A: Draw the outline, shape, title bar, and scroll bar of a window directly in the definition of the window class. However, there is a premise that we draw a window based on what platform, of course, it can be windows, GTK, QT, or MiniGUI. if we directly write the specific function implementation in the window class, the abstract part is the implementation part, and such implementation has a fixed dependence platform.
Another method is B: We do not directly implement the function in the window class. We inherit different subclasses from different platforms. For example, windowswindow is implemented for Windows platforms, gtkwindow is a Windows implementation for the GTK platform. such windows and gtkwindows are also implemented. they have implemented functional interface definitions in the abstract part. however, we can see that the functional interfaces in the implementation subclass are defined by window. If the subclass needs to add interfaces, the window must be dynamic. If the window is dynamic, the subclass must also be dynamic. that is, the abstract part and the implementation part are coupled, that is, there is no separation.
"ChangeAbstractAnd itsImplementationSeparated so that they can change independently. "In method B, there is a coupling between the abstract part and the implementation part because of the inheritance relationship. Is there a way to decouple it? Method C:
Implementation, that is, our windowswindow and gtkwindow do not inherit from the window class, but aggregate windows or gtkwindow to implement the window function. In this way, will the abstraction and implementation be separated? Can it be changed independently?
C. Question:
(1) Why is the bridge mode?
The abstract part and the implementation part are not inherited, but the abstract Part aggregates the implementation part. Such a link is called a bridge.
(2) When to use it?
When the abstract Part and implementation part need to be separated.
When both the abstract part and the implementation part can be expanded by generating sub-classes.
...