About Bridge Mode

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.