简体   繁体   English

Android MVP-演示者显示值(最佳做法)

[英]Android MVP - Presenter displaying values (best practices)

I started to learn MVP but I have a few questions related the Presenter . 我开始学习MVP,但是我有一些与Presenter有关的问题。 For example, if I have a really simple Activity that only displays a few information that I got from another Activity . 例如,如果我有一个非常简单的Activity ,它仅显示从另一个Activity获得的一些信息。 At the moment I am just displaying the value without sending it to the Presenter . 目前,我只是显示值,而没有将其发送给Presenter

Should I send the values to the Presenter so that the Presenter will call the methods in my Activity to display? 我是否应该将值发送给Presenter,以便Presenter调用我的Activity中的方法进行显示? Or can I just "ignore" the Presenter ? 还是我可以“忽略” 主持人

Should I send the values to the presenter and the presenter will call the methods in my activity to display? 我应该将值发送给演示者,演示者将调用活动中的方法进行显示吗?

You should. 你应该。

Or can I just "ignore" the presenter? 还是我可以“忽略”演示者?

You better should not. 你最好不要。

One of the benefits of structuring your code using the MVP pattern is the ability to unit test the structural units. 使用MVP模式构造代码的好处之一是可以对结构单元进行单元测试。 Any Presenter should be framework- (in Android , meaning view- ) independent which makes it possible to unit test it. 任何Presenter都应独立于框架(在Android中为view-),这样可以对其进行单元测试。 So, if you "ignore" the Presenter you won't be able to unit test the Activity methods invocations. 因此,如果您“忽略” Presenter ,则将无法对Activity方法调用进行单元测试。

For commercial app development unit testing is a relevant part. 对于商业应用程序开发,单元测试是相关的部分。

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

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