Gang of Four says: The Bridge pattern is to de-couple an abstraction from its implementation so that
the two can vary independently.
intent: decouple a set of implementations from the set of objects using them;
problem: the derivations of an abstract class must use multiple implimentations without causing an
explosion in the number of classes;
solution: define an interface for all implementaions to use and have the derivations of the abstract
class use that;
Participants and Collaborators: The Abstraction defines the interface for the objects being
implemented. The Implementor defines the interface for the specific implementation classes. Classes
derived from the Abstraction use classes derived from the Implementor without knowing which
particular ConcreteImplementor is in use.
Consequences: The decoupling of the implementations from the objects that use them increases
extensibility. Client objects are not aware of implementation issues.
Implementation:
1. Encapsulate the implementations in an abstract class
2. Contain a handle to it in the base class of the abstraction being implemented.
One way of measuring the quality of a design is to see how well it handles variation.
GOF: Bridge模式是把抽象和实现分离,以使得二者可以独立改变
目的:分离实现集和使用它们的对象集;
问题:对抽象类的继承必须使用多重实现以免带来类数量的膨胀;
解决方案:为所有的实现定义一个接口;
参与者和合作者:抽象层为被实现的对象定义了接口。实现定义了特定的实现类的接口。从抽象层的类集成使用从
实现者继承下来的类,但并不知道使用的是哪种特定的具体实现。
结果:从使用它们的对象中分离实现增长了可扩展性。客户对象不用关心实现细节。
实现:1 把实现封装在一个抽象类中
2 在被实现的抽象基类中包含一个它的句柄
衡量一个设计的质量的方法就是看它对变化的支持程度。