Skip to main content

How does it reduce coupling between objects?

The Mediator pattern reduces coupling between objects by replacing direct links between them with a single point of interaction, a centralized mediator.


1. Without a Mediator, a Full Mesh of Dependencies

If objects interact directly, each one has to know about the others: who exists in the system, what methods they have, when to call them.

Example: In a registration window, the Email field tells the Login button when to activate, and the button, in turn, calls PasswordField methods for validation.

The result is a "web-like architecture", where changing one component requires edits everywhere else.


Each component only knows one participant, the mediator:

java
class Button { private Mediator mediator; public void click() { mediator.notify(this, "click"); } }

The mediator receives events from components and decides who should react:

java
class DialogMediator implements Mediator { private Button loginButton; private TextBox emailField; private TextBox passwordField; public void notify(Component sender, String event) { if (sender == emailField || sender == passwordField) loginButton.setEnabled(!emailField.isEmpty() && !passwordField.isEmpty()); } }

Now EmailField, PasswordField, and Button don't know about each other, they simply "report the news" to the mediator.


3. What This Gives You

  • Weaker coupling, each object knows only the Mediator, not dozens of other components.
  • Easy modification, a new component can be added without changing the others.
  • Reusability, components become independent and can be used in other contexts.
  • Simplified interaction logic, all the behavior between objects is now concentrated in one place.

4. Analogy

Without Mediator, it's as if every airplane pilot communicated directly with every other pilot. With Mediator, all pilots talk only to the dispatcher, and the dispatcher decides who should act and when.


Conclusion

The Mediator pattern reduces coupling because it:

  • replaces many direct links with one central one,
  • makes components independent and reusable,
  • concentrates interaction in one place, simplifying maintenance and the evolution of the system.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.