antoniolg / androidmvp

MVP Android Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interactor what in MVP

tangdekun opened this issue · comments

commented

Why do we use Interactor in Mvp ?Presenter can maka it What Interactor do,can I see it as a model?or,it is a model

Interactors are an important part of many clean architectures, and are use cases of the App. It's true they are not very important in this example if the only goal is to learn MVP.

commented

Are Interactors used to manage data Like Model in MVP?

They are the part of the model that the presenters interact with, yeah.

commented

Thank you very much

For every use case, for example getting user profile and updating user profile I should create a separate interactor?

I would create at least separate interfaces. In some cases both could be implemented by one class.

commented

Hi Antonio. Got here after going through your site. I was hoping to get your advice about the flow I have going. It goes like this.

Activity > Presenter > Interactor > Helper
Activity < Presenter < Interactor < Helper

  • Activity - represents the view.
  • Presenter - the presenter class.
  • Interactor - the class that directly interacts with the helper and presenter classes. One separate interactor for each Helper class, implementing pretty much the callbacklisteners and corresponding presenter methods.
  • Helper - a specific class I use for Firebase DB calls.

Does how I use the interactor make sense here? Cheers!

@yelsane usually an interactor is usually called use case. It's a specific action that the user or our App starts. Usually an interactor tends to have just one execute method, because the name of the interactor itself already gives enough info.

There are some variations of this, but that usually is the way to use it. If your interactors are having that meaning, then I don't see anything wrong on the flow you describe. Looks good to me.

commented

@antoniolg Thank you so much for taking the time to provide feedback Antonio. I'll proceed with what I already have then. Cheers! 👍 👍

In this example you have made an interactor (which represents the model layer in MVP) instance in the presenter class but i know that model is represented as Singleton in the MVP architecture so is there a difference or affect on app performance
and which is better after all???

Well, singletons has their own problems. Main one is that it's difficult to implement, but also you have it in memory even when you don't use it.

If you are sure that it needs to be a singleton, I'd just make classes unaware of this implementation detail, by declaring the dependency in the constructor of the classes that use it.