android MVP - can I have multiple presenters for custom views and fragments
View (Activity)
can have multiple Presenters
. In case of having multiple CustomViews
for Activity
, you can have one giant Presenter
or Presenter
per each CustomView
. It depends on this:
If all
CustomViews
share same needs, onePresenter
for allCustomViews
is enough. Still two options forPresenter's
scope:Presenter
has ActivityScope.Activity
usesPresenter
and gets called fromPresenter
. Then sends commands, data toCustomViews
Presenter
has ViewScope. EachCustomView
creates and destroys samePresenter
In case of
CustomViews
not sharing same needs, having onePresenter
andViewInterface
, they will contain methods of allCustomViews
needs, so eachCustomView
has to implement all declared methods inViewInterface
, leave some empty.If
CustomViews
have different needs and method calls toPresenter
, they should have their ownPresenter
.- If
CustomViews
have different needs and also some common needs, they share common need in onePresenter
, specific needs in their ownPresenters
. Example for this:ActivityOne
hasCustomViewOne
andCustomViewTwo
. CommonPresenter
for bothCustomViews
can beFeedPresenter
(considering both CustomViews have Feed List). ThenCustomViewOne
will haveCustomPresenter1
andCustomViewTwo
will haveCustomPresenter2
for their specific needs.
Best practice is to create a basepresenter , then create presenter for each view implementing basepresenter