Bridge Pattern Structure and Components
What you'll learn: The four key players in the Bridge pattern and what role each one performs.
The Four Roles
The Bridge pattern divides responsibility among four components, each with a specific job:
1. Abstraction
This defines the high-level interface that clients interact with. It maintains a reference to an Implementor and delegates the actual work to it. Think of this as the remote control's interface—buttons labeled "power," "volume up," etc.
2. Refined Abstraction
These are subclasses of Abstraction that add specialized behavior or combine operations in new ways. For example, an AdvancedRemote might add a "mute" button that uses existing implementor operations.
3. Implementor
This is an interface (or abstract class) that declares low-level operations. It doesn't need to match the Abstraction's interface exactly. Think of this as the interface every TV brand must support: "turn on circuit," "adjust signal strength," etc.
4. Concrete Implementor
These are the actual implementations of the Implementor interface. Each represents a different platform or approach—like SonyTV, SamsungTV, or LGTV.
How They Work Together
The Abstraction holds a reference to an Implementor object and calls its methods. This means you can switch out the implementor without changing the abstraction's code. The Refined Abstraction adds extra features but still delegates low-level work to the same implementor.
Analogy: Your universal remote (Abstraction) can control any TV (Implementor) regardless of brand. A fancy remote (Refined Abstraction) might add presets, but it still sends the same basic signals to the TV.
Key Takeaway: The Bridge pattern uses four components—Abstraction, Refined Abstraction, Implementor, and Concrete Implementor—to separate what you do from how you do it, allowing both hierarchies to evolve independently.