简体   繁体   English

Android Mvp,主持人

[英]Android Mvp, presenter

I have read, and try to implement mvp pattern on Android for a while.. However, I never find an example that show activity's presenter, and fragment's presenter at the same time? 我已经阅读了一段时间,尝试在Android上实现mvp模式。.但是,我再也找不到一个示例来同时显示活动的演示者和片段的演示者?

As both Activity and Fragment consider as view. 由于Activity和Fragment都被视为视图。 And view is control by presenter. 并且视图由演示者控制。

Sometime activity is do nothing just for host fragment, but sometime it does many things such as contain many fragments and receive all input info from them and finally call restful service for save all data. 有时活动仅对主机片段无效,但有时它会做很多事情,例如包含许多片段并接收来自它们的所有输入信息,最后调用restful服务来保存所有数据。

QUESTION

Since most of the time activity is just for host the fragment, does it really need to have presenter? 由于大部分时间的活动仅是片段的宿主,因此确实需要主持人吗?

If not, when activity need to call rest api, how should they do. 如果不是,当活动需要调用rest api时,它们应该怎么做。 (according to map pettern) (根据地图样式)

If yes, don't you feel it's too overhead for create extra classes. 如果是,那么您是否觉得创建额外的类的开销太大。 Because most of the time, activity is for hosting fragment. 因为大多数时候,活动是用于托管片段。 Also, I really want to know how you guy name the class... 另外,我真的很想知道你们如何给班级命名...

For example, currently I have AbcActivity.class, AbcFragment.class, AbcPresenter.class(For fragment), AbcContract.class (Contain view, presenter interface)... what next ?? 例如,当前我有AbcActivity.class,AbcFragment.class,AbcPresenter.class(用于片段),AbcContract.class(包含视图,演示者界面)...接下来是什么? AbcActivityPresenter ?? AbcActivityPresenter ??

Sorry, for long typing, i'm ask from stack exchange app. 抱歉,要长时间输入,请从堆栈交换应用程序询问。

I have create a blog post about MVP http://www.nonvoid.com/model-view-presenter/ 我创建了有关MVP的博客文章http://www.nonvoid.com/model-view-presenter/

Yes, 是,

  • The activity needs the presenter. 该活动需要主持人。
  • The fragment does not have a presenter. 该片段没有演示者。
  • The presenter tells the activity what to display but doesn't care about the implementation details. 演示者告诉活动显示什么,但不关心实现细节。
  • There could be one, many or no fragments in an activity. 一个活动中可能有一个,很多或没有片段。 The presenter doesn't care. 演示者不在乎。

You'll see from my blog post that the " over head " is negligible compared to the added maintainability. 你会从我的博客文章认为,“ 头顶 ”相比,增加的可维护性是微不足道的看到。 The REST API calls should be encapsulated in the presenter. REST API调用应封装在presenter中。

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

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