1 00:00:00,780 --> 00:00:06,420 Let's take a look at the mediator interface first, so we have two minutes here at college and send 2 00:00:06,420 --> 00:00:11,630 a message, send messages for sending the respective message to their respective user. 3 00:00:11,820 --> 00:00:19,780 But the ad will be important because we need to make sure that the mediator knows about the colonics, 4 00:00:19,800 --> 00:00:22,430 knows about all the users of the chat application. 5 00:00:23,190 --> 00:00:28,560 On the other hand, a colleague interface has two minutes to send and receive message. 6 00:00:28,600 --> 00:00:30,780 So these are pretty straightforward. 7 00:00:31,110 --> 00:00:35,450 The first one is used for sending the message and the other one for receiving it. 8 00:00:35,730 --> 00:00:42,210 The concrete mediator has a list of colleagues that is used for storing all the users of the chat application 9 00:00:42,970 --> 00:00:44,060 in the constructor. 10 00:00:44,070 --> 00:00:52,770 The list is instantiated to an array and as you can see, the ad will be used for adding those users 11 00:00:52,770 --> 00:00:55,030 of the application to this list. 12 00:00:55,290 --> 00:01:03,630 Also, this same message method will make sure that the message won't be received by the user that has 13 00:01:03,630 --> 00:01:06,960 sent the message, otherwise it won't be sent. 14 00:01:06,980 --> 00:01:14,280 So all the other colleagues, all the other users will receive the message that was sent by by end user. 15 00:01:14,700 --> 00:01:16,160 The concrete call. 16 00:01:16,170 --> 00:01:22,740 The class has mediator object and the name for for the respective user. 17 00:01:23,170 --> 00:01:30,210 As you can see, we instantiate those in the constructor to send a method here will output the name 18 00:01:30,210 --> 00:01:36,210 of the user that has sent the message and also the message itself and will call the mediator for sending 19 00:01:36,210 --> 00:01:42,960 the message from the perspective of this of this user and receive, as you can see, it will output 20 00:01:42,960 --> 00:01:50,760 only a system out print and then a message which will tell the name of the of the person of the user 21 00:01:50,940 --> 00:01:54,750 and also the message that was received. 22 00:01:55,530 --> 00:01:58,080 Let's take a look now at the main method. 23 00:01:58,080 --> 00:02:05,280 So here we instantiate the mediator we instantiate to a concrete mediator because this is the implementation 24 00:02:05,760 --> 00:02:13,200 of this interface and also calling one colleague to we give them a name and also we assign the mediator 25 00:02:13,200 --> 00:02:15,210 forum for both of these users. 26 00:02:15,870 --> 00:02:26,190 Then we add the two users to the mediators underlying areolas in order for it to to make it aware that 27 00:02:26,190 --> 00:02:28,850 there are two users in the application. 28 00:02:29,160 --> 00:02:34,590 And here we just send a message from the perspective of the user one. 29 00:02:34,980 --> 00:02:39,110 And this should be seen by all the users of the application. 30 00:02:39,120 --> 00:02:41,060 So let's see this in practice. 31 00:02:41,070 --> 00:02:42,780 Let's run this main method. 32 00:02:44,030 --> 00:02:51,290 So as you can see, the name of the person that has sent the message is is displayed here with with 33 00:02:51,320 --> 00:02:54,320 the content of the screen that contains the message. 34 00:02:54,530 --> 00:03:00,730 And also you can see that the other participants in the chat received the message. 35 00:03:01,010 --> 00:03:03,860 So this is the implementation of this pattern. 36 00:03:04,550 --> 00:03:10,640 As you can see, the objects are not communicating between each other, but they are relying on an external 37 00:03:10,640 --> 00:03:13,940 object on a mediator to mediate the dialogue between them. 38 00:03:14,090 --> 00:03:22,190 So this can be very, very useful in situations when you have multiple, multiple objects that are communicating 39 00:03:22,190 --> 00:03:22,830 with each other. 40 00:03:23,000 --> 00:03:31,370 So instead of having a very, very complex scenario where you have to exchange various messages between 41 00:03:31,370 --> 00:03:36,830 various objects, you just send those messages to a mediator and the mediator will take care of the 42 00:03:36,830 --> 00:03:40,090 message and we'll send it to the relevant colleague. 43 00:03:41,300 --> 00:03:43,280 So that's it for this tutorial. 44 00:03:43,790 --> 00:03:45,020 Join me in the next one. 45 00:03:45,140 --> 00:03:47,750 We are going to discuss about the momento pattern.