Mediator

AKA: Director

When a set of objects react to each other’s state changes, the interactions can become complex. The objects involved become coupled to their specific use case and their relationships with the other objects. The objects may have had to derive from the regular objects to handle the need to send updates to their colleagues in the larger solution while avoiding cascading recursive calls.

A mediator or director object coordinates behaviour when specialising other objects is impossible or not desired. It reduces the need to write specific update code targeting specific objects, increasing the reusability of the interacting components because they no longer need role-specific customisation.

When an object would otherwise have had to inform a neighbouring object about its change, A mediator listens for changes in objects from generic endpoints. It can use Observer to achieve this. It responds to messages by issuing further messages to other objects. In fact, a mediator can usually be mostly implemented as a switchboard using multiple subscribers to decouple the implementation. The Mediator is an extraction of responsibility to inform into an object—a nominalisation of the specific relationships between instances.

“Let me coordinate this whole thing.”