您的位置:首页 > 其它

Design Patterns -- Bridge

2006-06-22 10:24 232 查看
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:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: