In MVP pattern, should Presenter be activity-wise or functionality-wise of Android app

242 views Asked by At

While building Android App using MVP pattern, I am wondering should I use presenter activity-wise or functionality-wise?

Activity-wise means, number of presenters equivalent to number of Activities.

Functionality-wise means, for each functionality, should use separate Presenter.

3

There are 3 answers

0
Marcos Vasconcelos On

Functionality-wise, so you can reuse presenters in multiple activities.

Also: A Presenter should not have references for Views or even Context for testing purposes.

1
Bassem Wissa On

My personal approach is that it depends on the logic, each has it's pros and cons. Let's say an activity has a list fragment and a details fragment, if theses fragments you are pretty sure they will only be used with this activity then you can have one presenter, but what if you want to use the detail or the list fragments in other activities, or if it's a list of people and the detail for each person, then you can open the logged in user detail view ( from a place other than the people list) ? you will use the same presenter of the activity ( not that good architectural wise ) so in this case having 2 presenter in my own opinion is a better approach!

To cut it short, there's no rule for it, it just depends whether if you are going to use the views in other scenarios or the view is only attached to this Activity.

2
Velmurugan V On

To me it should be Activity-wise as a screen may have more functionalities and having presenter for each one of them will require way too many presenter and also organising them into one screen will be a pain. Between it is a opinion based question.