Bridge Design Pattern

Intent

The Bridge Design Pattern

Intent

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

Motivation by Example

Motivation by Example

We want to support multiple operating systems:

DP Bridge Windows OS

We want to provide different types of windows:

DP Bridge Windows Types

Motivation by Example

Two dimensions of variability!

DP Bridge Windows No Solution

Several problems:

Structure

Structure

DP Bridge Structure

Combine inheritance and object composition:

Bridge-Based Designs Illustrated

DP Bridge Windows BridgePatternApplied

The Rationale Underlying the Solution:

Inheritance allows adding of new field and methods.

Composition demands a fixed interface.

Advantages

Decoupling interface and implementation:

Improved extensibility:

Takeaway

The Bridge Pattern instructs to use object composition to bridge between two inheritance hierarchies when you need to combine two kinds of variations of an object type.

The Bridge Pattern allows to vary an abstraction and its implementation independently of each other.

Works well as long as there is no dependency between the implementation on abstraction variations, i.e., if they do not vary co-variantly.