androidkotlinmvvmandroid-mvvmandroid-mvp

ANDROID MVP Interactor vs MVVM Repository


I understand MVVM has View - Viemodel -> Repository flow in which repository is in charge of taking care of api calls, database calls...

On the other hand in MVP we have View - Presenter - Interactor. From my opinion Interactor in MVP is very similar to repository in MVVM. They both do network and database calls with service and they send the results to Viewmodel/Presenter.

I would like to know a little bit more about this Interactor - Repository correlation. Is it true that if we have Interactor in MVP architecture, we don't need Repository class since the network layer is already separated in Interactor class? Also can we say that Interactor in MVP is almost the same thing as repository in MVVM? What are their differencies?


Solution

  • The Interactor represents a logical use case. The interactor is more like bridging the gap between the View layer (by communicating with the presenter) on one hand, and the implementation environment, or repositories, on the other. The interactor is used to have a clear picture of the use cases you want to develop in your application.

    Repositories, as you mentioned provides us with clean API to access the data layer and pass on the data to the domain layer(interactor/use cases).

    Is it true that if we have Interactor in MVP architecture, we don't need Repository class since the network layer is already separated in Interactor class? Answer-- No Because we want to avoid objects that deals with both presentation logic and dataflow logic. We also want the dataflow logic to be reusable across different ViewModels. Thus its better not to call the repository directly from the ViewModel/Presenter and have an additional interactor/usecase to handle that.

    For reference - https://proandroiddev.com/why-you-need-use-cases-interactors-142e8a6fe576