Adapter as Presenter? Or talking with a Presenter? Android and MVP

折月煮酒 提交于 2019-12-06 00:00:22

问题


I'm trying to follow the MVP pattern. However, I have some doubts on how to handle adapters and view holders on this pattern.

Should I use the adapter as a presenter? Having the business logic?

Or should I pass a instance of the presenter that handles the list logic and then call methods of the presenter when there is any interaction with the adapter elements?

Thank you


回答1:


There is no exact/correct definition of implementing MVP in Android

To answer your question, in my view the Presenter should not have any Android logic.

As such, the Adapter would be a "View" then i.e. Presenter provides it the data (via the Activity or Fragment) and it just deals with how to present this.

I'd do MVP as follow.

  1. Model - POJO's, parsing, Storing (SQLlite) and retrieving data (http). Obviously I'd divide the POJO's, parsing and DB logic into sub folders - but this all falls into Model for me.

  2. View - Activity, Fragment, Adapters - Activities & Fragment hold reference to a Presenter that gives them data to display. How this data/messages are displayed, look + feel etc. is dealt with in the View.

  3. Presenter - The Middle man, provides the logic to inputs i.e. Button Clicks, retrieval of data, validation of inputs & then passes the result back to the View (Activity or Fragment)

Here's a great article on MVP

Here's a simplified diagram of MVP

Answer modified from this question (also answered by me)



来源:https://stackoverflow.com/questions/34179914/adapter-as-presenter-or-talking-with-a-presenter-android-and-mvp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!