Android MVP – Presenter with multiple models
It is planned to implement MVP architecture for MVC Android applications. I am worried about how to make the host have multiple role models
Typically, the presenter's constructor will look like this:
In this way, I can exchange dependencies during testing and easily simulate views and models. But imagine that my host is associated with an activity that must be multiple network calls. Therefore, for example, I have an activity to log in API calls, and then another activity for security issues, Then perform the third activity on getfriendslist. All these calls are in the same activity topic. How do I use the constructor shown above to perform this operation? Or what is the best way to do this? Or am I restricted to one model and invoked service in the model?
resolvent:
Presenter constructors only need views. You don't have to rely on models. Define your presenters and similar views
public interface Presenter{
void getFriendList(Model1 model);
void getFeature(Model2 model2);
public interface View{
void showFriendList(Model1 model);
void showFeature(Model2 model2)
}
}
Now your implementation class depends only on the view part
Rest your method will handle your model
class PresenterImpl implements Presenter{
View view;
PresenterImpl(View view){
this.view = view;
}
void getFriendList(Model1 model){
//Do your model work here
//update View
view.showFriendList(model);
}
void getFeature(Model2 model2) {
//Do your model work here
//updateView
view.showFeature(model2)
}
}