Bridge Design Pattern
The Bridge design pattern is a structural pattern that decouples an abstraction from its implementation so that the two can vary independently. It's particularly useful when both the abstraction and its implementation may evolve separately or when you need to switch implementations at runtime.
🔷 Intent
"Decouple an abstraction from its implementation so that the two can vary independently."
🔷 Problem
In many object-oriented systems, classes often grow into hierarchies to handle variations in:
Abstractions (e.g., different UI controls like , )
Implementations (e.g., different OSes like Windows, Mac, Linux)
🔷 Solution
Split the class into two separate hierarchies:
Abstraction – defines the high-level interface
Implementation – defines the low-level platform-specific implementation
The Abstraction holds a reference to an Implementor and delegates the real work to it.
.
🔷 Structure
🔷 Example in Java
🔷 Benefits
Decouples interface from implementation
Improves extensibility: new abstractions and implementations can be added independently
Reduces subclass explosion
Enables runtime switching of implementations
🔷 When to Use
When you want to separate abstraction and implementation
When abstractions and implementations should be independently extensible
When changes in implementation should not impact the abstraction
🔷 Real-world Examples
UI Toolkits: abstraction with platform-specific renderers (, )
JDBC API in Java: JDBC provides an abstraction, and drivers provide implementations
File format exporters: can export using different strategies (, )