Summary
In this chapter, we looked at the Mediator pattern, which allows us to cut the ties between collaborators, mediating the communication between them. Then we studied the CQS pattern, which advises the division of software behaviors into commands and queries. Those two patterns are tools that cut tight coupling between components.
Afterward, we packed the power of a CQS-inspired pipeline with the Mediator pattern into a Clean Architecture application that uses MediatR, an open source library. We broke the coupling between the request delegates and the use case handler (previously a service). A simple DTO, such as a command object, makes endpoints and controllers unaware of the handlers, leaving MediatR as the middleman between the commands and their handlers. Due to that, the handlers could change along the way without impacting the endpoint.
This concludes another chapter exploring techniques to break tight coupling and divide systems into smaller parts. All those building...