Bridge Pattern
This lesson discusses how parallel class hierarchies or layers can be decoupled from one another using the bridge pattern.
We'll cover the following
What is it ?
A physical bridge provides connectivity between two points. The bridge pattern describes how to pull apart two software layers fused together in a single class hierarchy and change them into parallel class hierarchies connected by a bridge.
The bridge pattern can be applied to scenarios where the class and what it does changes often. Think of it as two layers of abstraction. The class itself becomes one layer and what it does i.e. the implementation becomes another layer. This setup allows us to extend the two layers independently of each other. In Java, both the layers would be represented by two separate class hierarchies. The bridge sits between these two class hierarchies, allowing the class abstraction to configure itself with the implementation abstraction.
Formally, the bridge pattern lets you vary the abstraction independently of the implementation, thus decoupling the two in the process. However, the abstraction and the implementation in the definition don't mean Java's abstract class/interface and concrete classes respectively.
Get hands-on with 1400+ tech skills courses.