Design Patterns    |     Security    |     Testing    |     Distributed Computing    |     Contact

Bridge

Definition

Decouple an abstraction from its implementation so that the two can vary independently.

Class Diagram

Bridge

Participants

  • Abstraction.
    • defines the abstraction's interface.
    • maintains a reference to an object of type Implementor.
  • RefinedAbstraction.
    • extends the interface defined by Abstraction.
  • Implementor.
    • defines the interface for implementation classes. This interface doesn't have to correspond exactly to Abstraction's interface; in fact the two interfaces can be quite different. Typically the Implementation interface provides only primitive operations, and Abstraction defines higher-level operations based on these primitives.
  • ConcreteImplementor.
    • implements the Implementor interface and defines its concrete implementation.

Benefits

  • Enables you to separate the interface from the implementation.
  • Improves extensibility.

Usage

  • When you want to avoid a permanent binding between an abstraction and its implementation.
  • When both the abstraction and implementations should be extensible using subclasses.
  • When changes in the implementation of an abstraction should have no impact on clients, which means that you should not have to recompile their code.