The bridge pattern
Remember that, at the beginning of the chapter, we discussed dynamic composition that allows you to change the implementation of an object at runtime. The bridge pattern is another structural pattern that allows this.
Roles
The bridge pattern decouples an abstraction from its implementation. This means that this pattern separates the implementation of an object from its representation and interface.
Thus, firstly, the implementation can fully be encapsulated, and secondly, the implementation and representation can independently change, without having any constraints between them.
This pattern can be used:
- To avoid a strong link between the object representation and its implementations
- To avoid any impact between the interaction of the objects and their clients when the implementations of objects are modified
- To allow the representation of objects and their implementations to keep their extension capability by creating new subclasses
- To avoid to obtain very complex classes hierarchies...