antoniolg / androidmvp

MVP Android Example
5.93k stars 1.58k forks source link

Interactor what in MVP #28

Closed tangdekun closed 6 years ago

tangdekun commented 7 years ago

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

antoniolg commented 7 years ago

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.

tangdekun commented 7 years ago

Are Interactors used to manage data Like Model in MVP?

antoniolg commented 7 years ago

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

tangdekun commented 7 years ago

Thank you very much

szaboa commented 7 years ago

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

OrdonTeam commented 7 years ago

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

yelsane commented 7 years ago

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

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

antoniolg commented 7 years ago

@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.

yelsane commented 7 years ago

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

MahmoudAmin39 commented 7 years ago

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???

antoniolg commented 6 years ago

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.