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:
本文深入解析了桥接模式的设计意图及实现步骤,旨在使抽象与其实现能够独立变化。通过实例说明如何重构类层次结构来应用此模式,并展示了具体的应用场景。
627

被折叠的 条评论
为什么被折叠?



