intermediateMediator Pattern

What problem does introducing a mediator object actually solve in a system where many objects need to communicate?

It replaces a web of direct references between every pair of communicating objects with each object holding a single reference to one central coordinator. Without a mediator, N objects that all need to talk to each other require roughly N-squared direct connections, and adding one more participant can mean updating many existing objects to know about it. With a mediator, every object needs exactly one reference — to the mediator — and the mediator is the only object that ever needs to know the full set of participants. This turns an unmanageable tangle of pairwise dependencies into a simple hub-and-spoke structure that is far easier to reason about and extend.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to How does the State pattern differ from simply using an enum with a switch statement to control behavior?← Back to all Low-Level Design & Design Patterns questions