LApplicability
NClass abstraction and its implementation should be expanded by generating sub-classes.
NIf any extension causes the class to grow with a geometric level, it means that you need to break down an object into two parts, which are called "nested generalization ".Nested generalizations";
LGenerally speaking,ImplementorOnly some basic operations are provided, whileAbastractionSome high-level operations based on these basic operations are defined.
LBridge patternAdvantages:
NYes, interfaces and implementations are separated. The implementation of an abstract class can be configured at runtime, and an object can even change its implementation at runtime.
NImprove the extensibility: You can separatelyInvalid actionOrImplementor.
NThe implementation details are transparent to the customer, and you can completely hide the details from the customer. InC ++Medium,ImplementorClass interfaces can be defined in a seemingly header file. This file is not provided to the customer, so that you can thoroughly hide the implementation of a class for the customer.
LImplementation
NOne special case is that there is only oneImplementorClass, which isBridge.
NInvalid actionThere are three methods to createImplementor;
UInvalid actionKnow allConcreteimplementor,So you can createImplementor;
UInvalid actionCreate a defaultImplementorAnd then change the implementation as needed;
UIntroductionFactory,This wayInvalid actionYou do not need to know any specificImplementor. I recommend this method.
Figure1Typical Structure of the Bridge Mode
AboutP106Mentioned inSet, sorted set, hashsetAndHistory List, hashtableIn the book, it is a kind of degraded bridge. I can also say this is a kindAdapter, We can look at the comparison of the two class results, as shown in the figure2And Graph3. Through comparison, we can find that,P106The application only has more sub-class implementations, which is equivalent to multipleAdapter.
The author also said this to the team,BridgeAndAdapterIt is similar.
Figure2Typical Structure of the adapter Mode
figure 3 p106 application mentioned in