Mediator Pattern
The Mediator pattern: routing the communication between many objects through one coordinator, and counting the links it removes.
A booking form has a trip type, two dates, a seat count and a book button, and changing any one of them can change several others. If each field holds a reference to every field it affects, the form becomes a web of links that nobody can follow. The Mediator pattern replaces the web with a star: each field tells one coordinator that it changed, and the coordinator decides what else must change.
This topic opens on that web of references, and counts how many links a mediator removes. It then reads the participants off the class diagram and follows one change through the mediator in a sequence diagram. The template runs three colleagues that never reference each other in Python, Java and TypeScript.
Two examples follow: the booking form, whose fields depend on each other, and a chat room, where the colleagues are many and alike. The gotcha is a mediator that collects every rule in the application, and the exercise counts the links an air traffic control tower removes.
By the end you can recognise a mediator, write one, and count what it saves and what it costs.
Contents
8 cardsnot started