What is the difference between Bridge and Adapter?
Answer
Both Bridge and Adapter involve wrapping one interface with another, but their intent and timing differ fundamentally. Adapter is applied after the fact to make two incompatible existing interfaces work together — it is a patch. Bridge is designed upfront to prevent a class hierarchy from growing exponentially when two independent dimensions of variation exist. Adapter changes the interface of an existing class without changing its behavior. Bridge defines both the abstraction and implementation interfaces from the start and keeps them separate so they can vary independently. If you're integrating a legacy class with a new interface, use Adapter. If you're designing a new class hierarchy with multiple varying dimensions, use Bridge.
Previous
How does the Command pattern support undo/redo?
Next
How does the Facade pattern differ from Mediator?
More Design Patterns (Gang of Four) Questions
View all →- Intermediate What is the Template Method design pattern?
- Intermediate What is the Visitor design pattern?
- Intermediate What is the difference between Factory Method and Abstract Factory?
- Intermediate When should you NOT use design patterns?
- Intermediate How are the Gang of Four patterns categorized?