Bridge
Intent
Splits a large class or closely related classes into two hierarchies, abstraction and implementation, that vary independently.
Problem
Shape × Colour subclasses explode: RedCircle, BlueCircle, RedSquare…
Solution
Use composition: the abstraction holds a reference to an implementation object.
Real-world analogy
One remote control (abstraction) can drive many TV brands (implementations). New remotes and new TVs evolve separately.
Structure
Hover or tap a numbered role to highlight it in the diagram.
- 1Abstraction — Abstraction provides high-level control logic and delegates low-level work to the implementation.
- 2Implementation — Implementation declares the interface common to all concrete implementations.
- 3ConcreteImplementation — Concrete Implementations contain platform-specific code.
- 4RefinedAbstraction — Refined Abstractions add variants of the control logic.
Code example
Applicability
Use Bridge when dividing a monolithic class with several variants.
Use Bridge when extending a class in independent dimensions.
Use Bridge when switching implementations at runtime.
Pros and cons
Pros
- Platform-independent abstractions
- Open–Closed on both sides
Cons
- More complex for highly cohesive classes
Relations with other patterns
Check yourself
Shapes (circle, square) must render with a vector or a raster renderer, and both lists keep growing.
Saved in this browser only. Part of Structural patterns (0/7).