Design pattern learning III: Bridge pattern

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 在被实现的抽象基类中包含一个它的句柄

衡量一个设计的质量的方法就是看它对变化的支持程度。

bridgepattern

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值