Let's take a look at the mediator interface first, so we have two minutes here at college and send
a message, send messages for sending the respective message to their respective user.
But the ad will be important because we need to make sure that the mediator knows about the colonics,
knows about all the users of the chat application.
On the other hand, a colleague interface has two minutes to send and receive message.
So these are pretty straightforward.
The first one is used for sending the message and the other one for receiving it.
The concrete mediator has a list of colleagues that is used for storing all the users of the chat application
in the constructor.
The list is instantiated to an array and as you can see, the ad will be used for adding those users
of the application to this list.
Also, this same message method will make sure that the message won't be received by the user that has
sent the message, otherwise it won't be sent.
So all the other colleagues, all the other users will receive the message that was sent by by end user.
The concrete call.
The class has mediator object and the name for for the respective user.
As you can see, we instantiate those in the constructor to send a method here will output the name
of the user that has sent the message and also the message itself and will call the mediator for sending
the message from the perspective of this of this user and receive, as you can see, it will output
only a system out print and then a message which will tell the name of the of the person of the user
and also the message that was received.
Let's take a look now at the main method.
So here we instantiate the mediator we instantiate to a concrete mediator because this is the implementation
of this interface and also calling one colleague to we give them a name and also we assign the mediator
forum for both of these users.
Then we add the two users to the mediators underlying areolas in order for it to to make it aware that
there are two users in the application.
And here we just send a message from the perspective of the user one.
And this should be seen by all the users of the application.
So let's see this in practice.
Let's run this main method.
So as you can see, the name of the person that has sent the message is is displayed here with with
the content of the screen that contains the message.
And also you can see that the other participants in the chat received the message.
So this is the implementation of this pattern.
As you can see, the objects are not communicating between each other, but they are relying on an external
object on a mediator to mediate the dialogue between them.
So this can be very, very useful in situations when you have multiple, multiple objects that are communicating
with each other.
So instead of having a very, very complex scenario where you have to exchange various messages between
various objects, you just send those messages to a mediator and the mediator will take care of the
message and we'll send it to the relevant colleague.
So that's it for this tutorial.
Join me in the next one.
We are going to discuss about the momento pattern.