关闭

Design Patterns -- Bridge

699人阅读 评论(0) 收藏 举报

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:

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:220018次
    • 积分:3637
    • 等级:
    • 排名:第8997名
    • 原创:132篇
    • 转载:19篇
    • 译文:1篇
    • 评论:22条
    文章分类
    最新评论
    其他