2

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.

raghav_si
  • 185
  • 1
  • 15

3 Answers3

2

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.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
2

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.

Bassem Wissa
  • 2,947
  • 1
  • 20
  • 20
  • 1
    Now I decided to make Presenters screen wise. Because I have to re-use those screens in many places.. thanks for your answer.. – raghav_si Sep 18 '17 at 14:05
0

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.

Velmurugan V
  • 428
  • 4
  • 12
  • What if One Activity has many fragments and only one presenter for all those, and in future want to use some of those fragments in another Activity?? – raghav_si Sep 15 '17 at 18:54
  • 1
    Actually, how i do is i will have one presenter per screen.So if your activity have many fragment have presenter for each fragments and if your activity have some view to render have presenter to activity also .Incase of list view ,I will have presenter to each views in the list – Velmurugan V Sep 15 '17 at 19:10