问题描述
请用一个简单的示例描述,MVP-Passive视图与MVP-Supervising Controller之间的差异.最好使用两种MVP技术 - 被动视图和监督控制器来验证使用控制数据并进行输入验证.谢谢
推荐答案
差异在视图层更新中.
来自 mode-view-view-presenter模式 MSDN上的页面:
更新模型时,还必须更新视图以反映更改.查看更新可以通过多种方式处理.模型视图的变体,被动视图和监督控制器,指定了实现视图更新的不同方法.
在被动视图中,主持人更新视图以反映模型中的变化.与模型的相互作用由主持人专门处理;该视图不知道模型中的变化.
在监督控制器中,该视图与模型直接相互作用,以执行简单的数据结合,可以声明地定义,而无需演示者干预.主持人更新模型;它仅在无法声明地指定的复杂UI逻辑的情况下才能操纵视图状态.复杂UI逻辑的示例可能包括更改控件的颜色或动态隐藏/显示控件.图1说明了被动视图和监督控制器变体的逻辑视图.
决定使用被动视图或监督控制器主要取决于您希望应用程序的测试方式.如果可测试性是您应用程序中的主要问题,则被动视图可能更合适,因为您可以通过测试演示者测试所有UI逻辑.另一方面,如果您更喜欢代码简单性,而不是完整的测试性,则监督控制器可能是一个更好的选择,因为对于简单的UI更改,您不必将代码包括在主持人中包含更新视图的代码.在被动视图和监督控制器之间进行选择时,请考虑以下内容:
- 这两个变体都使您可以提高演示文稿逻辑的可检验性.
- 被动视图通常比监督控制器提供更大的测试表面,因为所有视图更新逻辑都放在演示者中.
- 监督控制器通常需要比被动视图更少的代码,因为主持人不执行简单的视图更新.
进一步阅读:
被动视图:
http://martinfowler.com/eaadev/aadev/aadev/aadev/passivescreen.html
httpp ://codebetter.com/jeremymiller/2007/05/31/build-your-own-wown-cab-part-4-the-passive-view/
监督控制器:
问题描述
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: