design patterns · structural
Bridge
Decouples an abstraction from its implementation so both can vary independently.
Pattern
Overview
Intent
Decouple an abstraction from its implementation so that the two can vary independently.
Real-World Analogy
A TV remote (abstraction) controls any TV brand (implementation) without being tied to one manufacturer.
When you have two orthogonal dimensions of variation (e.g., shapes and rendering engines), using inheritance to cover every combination creates a class explosion. Bridge separates them into two independent hierarchies connected by composition.
The Abstraction holds a reference to an Implementor. The Abstraction delegates implementation-specific work to the Implementor. Both hierarchies can extend independently without touching each other.
When to use
When you want to avoid a cartesian subclass explosion - e.g., shapes × rendering engines, devices × remote controls, platforms × UI themes.
When not to
When there is only one implementation or the two dimensions do not vary independently.
Participants
Key Insights
- Bridge uses composition where inheritance would create O(n×m) subclasses
- The Implementor interface does not need to match the Abstraction interface
- Strategy pattern is similar but focuses on algorithms; Bridge focuses on structure
- Often used in cross-platform frameworks to separate UI logic from platform APIs