I'm building one Android app using MVP, and I have one question about this pattern.
Say I have one screen for creating a new person. This screen will show one EditText for inserting the name, another for the surname, one ImageView to show the picked photo picture, etc.
This will lead to one View interface, implemented by the Fragment. It will cooperate with one Presenter interface, implemented by another class.
Fine.
Now I have another feature: a screen for editing an existing person.
As it happens, the View for this feature is identical to the one for creating a new person. However, the Presenter is different. It will start by loading the existing person from db to pre-populate the view with the current data, and the action over the database when clicking "save" will be an update instead of a insertion.
So, I think this is an example of MVP where one View works with different implementations of the presenter to achieve different use cases.
Do you think this is a correct assumption, or do you think different features should have different
ViewandPresenterinterfaces?Also, if you'd with a common
Viewand differentPresenters, will the implementation of theViewbe common, or would it lead to the same interface implemented by two classes? In practice, I see two options.Having just one
Fragmentimplementing theView. Depending on whether the user is about to create a new person or update an existing one, the Fragment should receive and use a different Presenter.Having two
Fragments. Each one would instantiate a differentPresenter. Use composition or inheritance to avoid replication of code between the two fragments.
What do you think is better to do in these cases?
Thanks.