转换为主持人?或与主持人交谈? Android和MVP [英] Adapter as Presenter? Or talking with a Presenter? Android and MVP

查看:86
本文介绍了转换为主持人?或与主持人交谈? Android和MVP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循MVP模式.但是,我对如何处理这种模式的适配器和查看支架有一些疑问.

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?

或者我应该传递一个处理列表逻辑的presenter实例,然后在与适配器元素发生任何交互时调用presenter的方法吗?

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?

谢谢

推荐答案

在Android中没有实现MVP的准确/正确定义

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

要回答您的问题,我认为Presenter不应具有任何Android逻辑.

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

这样,Adapter将是"View",即Presenter向其提供数据(通过ActivityFragment),并且仅处理如何呈现此数据.

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.

我将按照以下步骤做MVP.

I'd do MVP as follow.

  1. 模型-POJO,解析,存储(SQLlite)和检索数据(http).显然,我将POJO,解析和DB逻辑划分为子文件夹-但这全都属于我的模型.

  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.

查看-ActivityFragmentAdapters-活动和片段持有者对演示者的引用,该演示者为他们提供了要显示的数据.在View中处理这些数据/消息的显示方式,外观和感觉等.

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.

演示者-中间人,提供输入逻辑,即按钮点击,数据检索,输入验证以及然后将结果传递回视图(ActivityFragment)

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)

这是关于 MVP

这是简化的

对此问题进行了修改的答案(我也回答了)

这篇关于转换为主持人?或与主持人交谈? Android和MVP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆