1 00:00:00,640 --> 00:00:07,690 The mediator pattern is a behavioral pattern used for mediating the exchange of messages between objects. 2 00:00:08,800 --> 00:00:14,470 The best analogy to a real world scenario for this batter is my thinking at an airport traffic control 3 00:00:14,470 --> 00:00:17,080 tower and its dialogue with the plane's. 4 00:00:18,410 --> 00:00:23,630 The police are not communicating between each other, but rather with the tower and the tower sends 5 00:00:23,630 --> 00:00:25,880 the relevant messages to other planes. 6 00:00:26,780 --> 00:00:29,900 This is exactly what you should achieve with the mediator pattern. 7 00:00:31,050 --> 00:00:36,810 You can use this pattern whenever you have too many relationships between the objects, making the dialogue 8 00:00:36,810 --> 00:00:38,210 between them too difficult. 9 00:00:39,700 --> 00:00:46,090 Also, when the communication between objects is very complex, it is worth adding a mediator and untangle 10 00:00:46,090 --> 00:00:47,860 some of the communication complexity. 11 00:00:49,290 --> 00:00:52,330 The UML diagram for this pattern is pretty straightforward. 12 00:00:52,740 --> 00:00:59,340 You have a mediator interface that is implemented by a concrete mediator class a colleague interface 13 00:00:59,340 --> 00:01:01,830 will be implemented by the concrete college class. 14 00:01:02,010 --> 00:01:07,350 And you can see that instead of the two colleagues communicating with each other directly, they rely 15 00:01:07,350 --> 00:01:09,960 on the mediator to mediate the communication. 16 00:01:11,170 --> 00:01:17,560 In our app, we will call the chat mediator and the role of the colleagues will be taken by the users 17 00:01:17,560 --> 00:01:18,250 of the chat. 18 00:01:20,060 --> 00:01:22,600 Let's now see the implementation for this father.