Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android MVP - can I have multiple presenters for custom views and fragments

So I have an a presenter that is already tied to an activity. The book says that one presenter should be tied to one view. But now I am adding a few fragments and lots of custom views. I am considering a fragment to be a view as well. The custom views will contain a little bit of logic in them. Both the fragments and custom views are contained in my activity of course.

My question is, should I re-use the same presenter in the fragment and custom views or should each view get its own presenter? I realize this is all opinion based but I want the best approach for testing and keeping code clean.

If i do have one presenter for all these fews then then interface the presenter uses will have many callback methods in it. Meanwhile if i did the opposite and created one presenter for each view it might be easier to read but how would i test it ?

like image 986
j2emanue Avatar asked Mar 29 '17 21:03

j2emanue


People also ask

Can a view have multiple presenters?

Your view can have several presenters, there can be one presenter in one fragment, or several presenters in one activity.

What is a presenter Android?

A Presenter is used to generate View s and bind Objects to them on demand. It is closely related to the concept of an RecyclerView. Adapter, but is not position-based. The leanback framework implements the adapter concept using ObjectAdapter which refers to a Presenter (or PresenterSelector ) instance.


1 Answers

Best practice is to create a basepresenter , then create presenter for each view implementing basepresenter

like image 144
vegeto Avatar answered Oct 04 '22 18:10

vegeto