Android MVP - can I have multiple presenters for custom views and snippets

So I have a speaker who is already associated with the activity. The book says that one lead should be tied to one view. But now I am adding a few fragments and many custom views. I view the fragment as a species. Custom views will contain some logic in them. Both fragments and user views are contained in my work, of course.

My question is, should I reuse the same presenter in a fragment and in user views, or should each view have its own presenter? I understand that all of this is opinion based, but I want a better approach for testing and keeping code clean.

If I have one presenter for all these few, then the interface that the presenter uses will have many callback methods. Meanwhile, if I did the opposite and created one presenter for each view, it would be easier to read, but how would I test it?

+7
source share
2 answers

View (Activity) Presenters. CustomViews Activity, Presenter Presenter CustomView. :

  • CustomViews , Presenter CustomViews. Presenter's:

    • Presenter ActivityScope. Activity Presenter Presenter. , CustomViews
    • Presenter ViewScope. CustomView Presenter

    CustomViews , Presenter ViewInterface, CustomViews , CustomView ViewInterface, .

  • CustomViews Presenter, Presenter.

  • CustomViews , , Presenter, Presenters. : ActivityOne CustomViewOne CustomViewTwo. Presenter CustomViews FeedPresenter (, CustomViews ). CustomViewOne CustomPresenter1, CustomViewTwo CustomPresenter2 .
+5

basepresenter, , basepresenter

+3

Source: https://habr.com/ru/post/1016149/


All Articles