Year End Sale: Get Upto 40% OFF on Live Training! Offer Ending in
D
H
M
S
Get Now

Behavioural Design Pattern: Mediator Design pattern

Level : Advanced
Mentor: Shailendra Chauhan
Duration : 00:01:00

Define Mediator Design Pattern

This pattern allows several objects to communicate with one another without knowing one other's structures. This pattern defines an object that encapsulates how the objects will interact with one another and allows the code to be easily maintained through loose coupling.

Examples of Mediator Design Patterns

Examples of the mediator pattern include:

  • Messaging
  • Chat

Mediator Pattern with UML diagram

The classes, interfaces, & objects in the above UML class diagram are defined as follows.

  • Mediator: This interface defines operations that colleague objects can use to communicate.
  • ConcreteMediator: This class implements the Mediator interface's communication operations.
  • Colleague: This class defines a single, protected field containing a reference to a mediator.
  • ConcreteColleagueA/B: These are the classes that communicate with one another through the mediator.

When should you use the Mediator Design Pattern?

The mediator design pattern is applicable in the following situations:

  • Communication among several things is well defined but potentially complex.
  • When there are too many relationships and a centralized source of control or communication is required.
  • Certain objects can be grouped and customized based on their activity.

Advantages of the Mediator Design Pattern

  • Reduced Complexity: It centralizes complex communications and controls the logic between system components.
  • Decoupled Objects: Colleague objects are less tightly coupled, which improves maintainability and reuse.
  • Simplified Object Protocols: Objects no longer communicate directly with one another, but rather through a mediator, resulting in simpler interaction protocols.
  • Centralized Control: The mediator encapsulates the logic for how objects interact, making it easier to alter the logic without affecting the other classes.
Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this