Card 02/ 08
Bridge Pattern Structure: The Class Diagram
Abstraction holds an Implementor, and each side has its own subclasses.
Bridge has four participants on two sides and a client. The abstraction side is what the client calls, and the implementor side is what does the low-level work. This card reads their roles off the Gang of Four's class diagram and names the one reference that joins the two sides.
| Participant | Role |
|---|---|
| Abstraction | The interface the client uses. Holds a reference to an Implementor and builds its operations from the implementor's. |
| RefinedAbstraction | A variant of the abstraction, such as an urgent notification, that adds or changes behaviour. |
| Implementor | The interface for the low-level operations, which need not look like the abstraction's. |
| ConcreteImplementor | One implementation of those operations, such as one channel or one database driver. |
| Client | Creates or receives an abstraction joined to an implementor, and calls the abstraction. |
The aggregation from Abstraction to Implementor is the bridge. Everything to its left can be subclassed without touching anything to its right, and the reverse. The implementor's interface is usually lower-level than the abstraction's: a shape's draw might call a renderer's line and arc several times.
Bridge looks like Strategy, an object holding an interface it delegates to. The difference is that a bridge's abstraction has its own hierarchy of variants, and the implementor is the whole platform beneath it, while a strategy is one interchangeable algorithm inside a single class.
← → move through sections and cards