简体   繁体   English

在MVP模式下,Presenter应该是Android应用程序的活动性还是功能性

[英]In MVP pattern, should Presenter be activity-wise or functionality-wise of Android app

While building Android App using MVP pattern, I am wondering should I use presenter activity-wise or functionality-wise? 在使用MVP模式构建Android App时,我想知道应该使用演示者活动还是功能?

Activity-wise means , number of presenters equivalent to number of Activities. 按活动量表示 ,与活动数量相等的演示者数量。

Functionality-wise means, for each functionality, should use separate Presenter. 功能明智的手段,对每个功能时,应使用单独的演示。

Functionality-wise, so you can reuse presenters in multiple activities. 功能方面,因此您可以在多个活动中重用演示者。

Also: A Presenter should not have references for Views or even Context for testing purposes. 另外:演示者不应出于测试目的而具有视图或上下文的引用。

My personal approach is that it depends on the logic, each has it's pros and cons. 我个人的方法是,这取决于逻辑,每个逻辑都有其优缺点。 Let's say an activity has a list fragment and a details fragment, if theses fragments you are pretty sure they will only be used with this activity then you can have one presenter, but what if you want to use the detail or the list fragments in other activities, or if it's a list of people and the detail for each person, then you can open the logged in user detail view ( from a place other than the people list) ? 假设一个活动有一个列表片段和一个细节片段,如果您确定这些片段只能用于此活动,那么您可以有一个演示者,但是如果您想在另一个片段中使用细节或列表片段呢?活动,或者如果它是人员列表以及每个人的详细信息,那么您可以打开登录的用户详细信息视图(从人员列表以外的地方)? you will use the same presenter of the activity ( not that good architectural wise ) so in this case having 2 presenter in my own opinion is a better approach! 您将使用活动的同一主持人(不是那么好的架构师),所以在这种情况下,以我个人的观点来看,有2个主持人是更好的方法!

To cut it short, there's no rule for it, it just depends whether if you are going to use the views in other scenarios or the view is only attached to this Activity. 简而言之,没有规则可言,它仅取决于您是否要在其他情况下使用视图,还是仅将视图附加到此活动。

To me it should be Activity-wise as a screen may have more functionalities and having presenter for each one of them will require way too many presenter and also organising them into one screen will be a pain. 对我来说,应该是活动型的,因为屏幕可能具有更多的功能,而为每个屏幕提供演示者将需要太多的演示者,而且将它们组织到一个屏幕中将是一件痛苦的事情。 Between it is a opinion based question. 在两者之间是一个基于意见的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM