Adapter vs Bridge: When to Use Which
You'll learn how to distinguish between the Adapter and Bridge patterns despite their structural similarities, focusing on their fundamentally different purposes.
The Key Difference: Intent
Though both patterns involve composition and delegation, Adapter is about compatibility while Bridge is about flexibility.
Adapter Pattern solves a problem after the fact. You have two incompatible interfaces that need to work together—perhaps legacy code meeting new requirements, or a third-party library that doesn't match your system's expected interface. The Adapter wraps one interface to make it compatible with another.
Bridge Pattern is proactive design. You anticipate that both your abstraction and its implementation will evolve independently. You separate them from the start so changes to one don't cascade into the other. The Bridge prevents an explosion of subclasses when you have multiple dimensions of variation.
Think of It This Way
Adapter: You bought a European power plug but your outlet is American. You need an adapter to convert one interface to another. The adapter exists because of incompatibility.
Bridge: You're designing a universal remote control system. You separate "remote control features" (abstraction) from "device communication protocols" (implementation) so you can add new remote types or support new devices without rewriting everything. The bridge exists because of anticipated variation.
When to Use Which
Use Adapter when:
- You need to integrate existing, incompatible components
- You're working with third-party code you can't modify
- You're solving a compatibility problem
Use Bridge when:
- You're designing from scratch with expected variations
- Both abstraction and implementation will change independently
- You want to avoid a Cartesian product of subclasses
Key Takeaway: Adapter is reactive (fixing interface mismatches), while Bridge is proactive (preventing design rigidity by separating orthogonal concerns from the start).