`
dr2tr
  • 浏览: 138712 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Design Patterns -- Bridge

阅读更多

1. The intent of the BRIDGE pattern is to decouple an abstraction (a  class that relies on a set of abstarct operations, GoF Design Patterns)  from the implementation of its abstract operation, so that the abstraction and its implementation can vary independently.

2. A Bridge structure moves the abstract operations that an abstraction relies on into a separate interface, pic:

Implementor contains the abstract operations seperated from Abstraction, and after seperation Abstraction  is concrete.

3. A common example of Bridge occurs in drivers using. An application that uses a driver is an abstraction -- the choice of driver determines what happens when the application runs.

4. Steps to refactor a hierarchy with an abstract class at lits top into a bridge:

a. Move the abstract operation in the superclass into an interface.

b.Define implementation classes that provide different implementations of the interface.

c. Redefine the remaining operations in the abstract class as operations on an instance of the new interface. (The remaining operations usually uses the functions in the interface).

5. Another example of Bridge:

ori:

sec:

after refactor:

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics