What is the Bridge Pattern and when to use it
masterThe Bridge pattern is a structural design pattern used to decouple an abstraction from its implementation so that the two can vary independently.
It is particularly useful when you face a 'class explosion' problem—where you find yourself creating a new class for every possible combination of two different dimensions (e.g., OnlineOrderWithPayPal, OnlineOrderWithStripe, InStoreOrderWithPayPal, etc.).
Use the Bridge pattern when:
- You want to avoid a permanent binding between abstractions and their implementations.
- Both abstractions and implementations should be extensible independently.
- Changes in the implementation should not impact the client code.
- You have a proliferation of classes resulting from a coupled interface and numerous implementations.
- You want to share an implementation among multiple objects.