什么是MVP无源视图和MVP监控控制器 [英] What are MVP-Passive View and MVP-Supervising controller

查看:161
本文介绍了什么是MVP无源视图和MVP监控控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请用简单的例子描述MVP-Passive View和MVP-Supervising控制器的区别。最好通过使用mvp技术 - 被动视图和监督控制器来显示控件中的数据是如何绑定和输入的。感谢

解决方案

区别在于视图层更新。



MSDN上的 Model-View-Presenter模式页面:


当模型更新时,视图也必须更新以反映更改。查看更新可以通过多种方式处理。模型视图呈现器变体,被动视图和监督控制器,指定实现视图更新的不同方法。



被动视图中,演示者更新视图以反映模型中的更改。与模型的互动完全由演示者处理;该视图不知道模型中的更改。



监督控制器中,视图与模型直接交互以执行简单的数据绑定可以声明地定义,没有主持人的干预。演示者更新模型;只有在不能声明性地指定复杂的UI逻辑的情况下,才会操纵视图的状态。复杂UI逻辑的示例可能包括更改控件的颜色或动态隐藏/显示控件。图1显示了被动视图和监督控制器变体的逻辑视图。



决定使用被动视图监督控制器主要取决于你想要应用程序的可测试性。如果可执行性是您的应用程序的主要关注点,则Passive View可能更适合,因为您可以通过测试演示者来测试所有的UI逻辑。另一方面,如果您希望代码简单性超出完全可测试性,则监督控制器可能是一个更好的选择,因为对于简单的UI更改,您不必在演示者中包含更新视图的代码。在被动视图和监督控制器之间选择时,请考虑以下内容:




  • 这两种变体都可以提高演示逻辑的可测试性。 li>
  • 被动视图通常提供比监督控制器更大的测试面,因为所有视图更新逻辑都放在演示者中。

  • 监督控制器通常需要的代码少于被动视图,因为演示者不执行简单的视图更新。


进一步阅读:

被动视图



http://martinfowler.com/eaaDev/PassiveScreen.html



http://codebetter.com/jeremymiller/2007 / 05/31 /建立你自己驾驶室部分-4-的被动视图/



监督控制器



http://martinfowler.com/eaaDev/SupervisingPresenter.html



http: //codebetter.com/jeremymiller/2007/05/25/build-you-own-cab-part-3-the-supervising-controller-pattern/


Please describe with a simple example, the differences between MVP-Passive View and MVP-Supervising controller. It would be better to show how data with control is binded and input is validated using both mvp techniques - Passive View and Supervising controller. Thanks

解决方案

The difference is in view layer updates.

From the Model-View-Presenter pattern page on MSDN:

When the model is updated, the view also has to be updated to reflect the changes. View updates can be handled in several ways. The Model-View-Presenter variants, Passive View and Supervising Controller, specify different approaches to implementing view updates.

In Passive View, the presenter updates the view to reflect changes in the model. The interaction with the model is handled exclusively by the presenter; the view is not aware of changes in the model.

In Supervising Controller, the view interacts directly with the model to perform simple data-binding that can be defined declaratively, without presenter intervention. The presenter updates the model; it manipulates the state of the view only in cases where complex UI logic that cannot be specified declaratively is required. Examples of complex UI logic might include changing the color of a control or dynamically hiding/showing controls. Figure 1 illustrates the logical view of the Passive View and Supervising Controller variants.

The decision to use Passive View or Supervising Controller primarily depends on how testable you want your application to be. If testability is a primary concern in your application, Passive View might be more suitable because you can test all the UI logic by testing the presenter. On the other hand, if you prefer code simplicity over full testability, Supervising Controller might be a better option because, for simple UI changes, you do not have to include code in the presenter that updates the view. When choosing between Passive View and Supervising Controller, consider the following:

  • Both variants allow you to increase the testability of your presentation logic.
  • Passive View usually provides a larger testing surface than Supervising Controller because all the view update logic is placed in the presenter.
  • Supervising Controller typically requires less code than Passive View because the presenter does not perform simple view updates.

Further reading:

Passive View:

http://martinfowler.com/eaaDev/PassiveScreen.html

http://codebetter.com/jeremymiller/2007/05/31/build-your-own-cab-part-4-the-passive-view/

Supervising controller:

http://martinfowler.com/eaaDev/SupervisingPresenter.html

http://codebetter.com/jeremymiller/2007/05/25/build-you-own-cab-part-3-the-supervising-controller-pattern/

这篇关于什么是MVP无源视图和MVP监控控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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