Role of Input Ports in Clean Architecture

Viewed 1268

Can you explain me what are the benefits of such abstraction as Input Ports in Clean Architecture? Why not use Interactors / Use Cases directly? I understand the role of Output Ports - this way use cases don't have to know about presenters and other adapters. But can't wrap my head around this one. In addition, is there any relation between repository interface and ports? Can repository interfaces be considered Input or Output ports? Thank you!

1 Answers

The Input and Output ports are nothing more than an application of the Dependency Inversion Principle of SOLID in clean Architecture. In most programming languages, they are interfaces (or abstract interfaces). If you look at the original diagram below.

You can see that Controller calls a method on Input Port interface, UseCase implements it, and then UseCase sends a response to the Output Port interface, which Presenter implements. In this case, all implementations of a part of the system can be replaced, since they depend only on the interfaces. enter image description here

Related