Bridge Pattern
The Bridge pattern: splitting what something is from how it is done into two hierarchies, so they grow without multiplying classes.
A notification can be urgent or routine, and it can go by email, SMS or push. Written as subclasses, every pair needs a class of its own, six of them, and a fourth channel adds two more. The Bridge pattern splits the two questions into two hierarchies, what is sent and how it is delivered, and joins them with one reference, so the classes add up instead of multiplying.
This topic opens on that problem and the intent, then reads the participants off the class diagram, where the reference from the abstraction to the implementor is the bridge itself. The template combines two abstractions with two implementors in Python, Java and TypeScript.
Two examples follow: notifications by urgency and by channel, with the classes counted both ways, and JDBC, where your code talks to Connection and each database supplies the driver behind it. The gotcha is a bridge built before a second dimension exists, and the exercise designs remote controls for several devices and counts what a new device costs.
By the end you can recognise a bridge, build one, and work out how many classes it saves.
Contents
8 cardsnot started