Mediator design pattern diagram The class Mediatorimplements a method sendthat accepts a message from a user and then forwards it to another user. Each user has a method receivefor receiving messages. I've also seen a two method approach. These can be for example methods commandand query. The main idea was to create dedicated methods for sending queries and commands in the system.
The purpose of the commands was tohe system. In turn the purpose of queries was to return results. This approach to the topic may be a good introduction to the implementation of the CQRS pattern in the system Phone Number List being built. Of course nothing prevents both inquiries and commands from being handled by the mediator using one method. Mediator – advantages and disadvantages Using Mediator brings several benefits.
First a separate component dedicated to communication helps you write code that complies with the Single Responsibility Principle . The second significant advantage is the reduction of coupling between classes. Objects that communicate with each other do not need to know anything about each other. A small number of dependencies also allows you to easily expand the system with new objects.