Design Patterns Mediator Pattern - Design Patterns

What is Design Pattern Mediator Pattern?

Mediator pattern is used to decrease communication simplicity between several objects or classes. This pattern provides a mediator class which normally handles all the communications between different classes and supports easy continuance of the code by loose coupling. Mediator pattern fall under behavioural pattern group.

Implementation

We are representative intermediary pattern by instance of a chat room where many users can send message to chat room and it is the task of chat room to explain the messages to all users. We have created two classes Chartroom and User. User objects will use Chartroom method to distribute their messages.

MediatorPatternDemo, our presentation class, will use User objects to prove communication between them.
mediator_pattern_uml_diagram

Step 1

Create mediator class.

ChatRoom.java

Step 2

Create user class

User.java

Step 3

Use the client object to explain communications between them.

MediatorPatternDemo.java

Step 4

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics