Decouple an abstraction from its implementation so both can vary independently. You need to support multiple implementations across multiple
Bridge
Overview
Decouple an abstraction from its implementation so both can vary independently.
When to use
- You need to support multiple implementations across multiple abstractions.
- You want to avoid a class explosion from combinations.
Java example
TypeScript example
Pros and cons
Pros:
- Avoids combinatorial subclasses.
- Implementations are swappable.
Cons:
- More indirection.
- Harder to trace behavior.
Common pitfalls
- Using Bridge when simple inheritance would do.
- Creating too many tiny abstractions.