Decoupling with Interfaces

Let’s learn about the drawbacks of loose coupling with our repository.

The clean architecture we’ve built in the previous chapters defines a use case that receives a repository instance as an argument and uses its list method to retrieve the contents. This allows the use case to form a loose coupling with the repository, which is connected only through the API exposed by the object. It isn’t connected to the real implementation. In other words, the use cases are polymorphic with respect to the list method.

This is very important and is the core of clean architecture design. When connected through an API, the use case and the repository can be replaced by different implementations, as long as the new implementation provides the requested interface.

Get hands-on with 1400+ tech skills courses.