Clean Architecture - Robert Martin - How to Connect Use Cases

Why controller has to call interface on use cases in Clean Architecture

Depending of the size and the complexity of ur project it would be perfectly fine to simply create the use case interactor with new in the controller and use the implementation directly.

However there are a few advantages of using interfaces (input ports):

  • Testing: in case u want to unit test ur controller code an interface would allow u to mock away the use case interactor
  • Dependencies: in case ur use case interactor has dependencies to domain services or repositories then u want to "wire those up" in ur "main component" and just pass the use case interactor via interface (input port) to the controller

For a more in depth discussion on controllers and presenters pls have a look at my blog post: http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/

Combining Use Cases/Interactors in Clean Architecture

In my opinion, you should develop the three interactors in order to respect the Single Responsability Principle. If you do that, you increase the maintainability and reutilization of the code, because you could use these interactors separately in other scenarios.



Related Topics



Leave a reply



Submit