MVP和UserControls和调用 [英] MVP and UserControls and invocation

查看:102
本文介绍了MVP和UserControls和调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些乐趣试图让我的头脑围绕一些MVP stuf,因为它属于用户控件。我使用.NET WinForms(或接近它的东西)和监督控制器模式(好吧,我想我是:)。

I'm having some fun trying to get my head around some MVP stuf, as it pertains to User Controls. I'm using .NET WinForms (or something close to it) and Supervising Controller pattern (well, I think I am :).

用户控件本身就是MVP应用程序的一部分(它的View和具有关联的Presenter等)。演示者始终首先启动,它启动模型,然后启动视图。该视图构建其UI,其中一部分将是新的UC,即View。

The User Control is itself part of an MVP application (its the View and has an associated Presenter etc). The Presenter is always started first, and it starts the Model(s) and then View(s). The View builds its UI, part of which will be to NEW the UC, which is the View.

现在(表格)Presenter需要了解UC Presenter,但我认为它不了解View如何构成任何内容。例如,Presenter的表单不知道UC是表单的Controls集合的一部分,也不应该。

Now the (form) Presenter needs to know about the UC Presenter, but I'm thinking that it doesn't know anything about how the View is composed. The form Presenter doesn't, for instance, know that the UC is part of the form's Controls collection, nor should it.

此外,设计经验不应该更改; IOW,View(form)的开发者应该能够从工具箱中选择一个User Control,并将其放在一个表单上。

Furthermore, the design experience should not be changed; IOW the dev of the View (form) should just be able to select a User Control from the toolbox and drop it on a form.

所以,就我的问题。首先,我上面的假设是否正确?有点误导了弄乱?你在想什么WTF?

So, on to my questions. Firstly, are my assumptions above correct? Somewhat misguided? Messed up? WTF are you thinking?

其次,View的形式是否正确(足够?)调用UC View,表单Presenter调用UC Presenter,并有一些机制告诉UC查看它的Presenter是什么?这打破了我的演讲者优先的规则,但我不知道如何做到这一点。

Secondly, is it right (enough?) to have the form View invoke the UC View, and the form Presenter invoke the UC Presenter and have some mechanism to tell the UC View what its Presenter is? This breaks my "Presenter first" rule, but I'm not sure how else to do it.

任何其他想法,建议,评论都很乐意接受。

Any other thoughts, suggestions, comments gladly accepted.

- nwahmaet

-- nwahmaet

推荐答案

演示层应该将演示者视为自治州。这意味着它有责任确保视图对模型状态的呈现同步。我提出的原因是因为MVP的模式通常会在应该分开的教条式观点中迷失。看来,这是Martin Fowler决定尝试澄清MVP 模式的术语的一个原因。

A presenter should be thought of as "autonomous state" in the presentation tier. This means that it is responsible for ensuring that the view's presentation of the model's state is in sync. The reason I bring this up is because the "pattern" of MVP often gets lost in the dogmatic view of how things should be separated. It seems that this is one reason Martin Fowler decided to try to clarify the terminology around the MVP pattern.

我喜欢MVP的风格是被动视图,所以我的答案是基于这一点。

My favored flavor of MVP is the passive view, so my answer is based off of that.

我通过使用被动视图模式来实现复合用户控件和表单。基本上有三种不同的配置:

I implement composite user controls and forms very often using the passive view pattern. There are essentially 3 different configurations:


  1. 层次结构中所有用户控件的一个主持人。使用界面对视图进行平铺。

  2. 复合树中每个用户控件的一个演示者。每个家长主持人负责实例化和初始化其小孩主持人。用户控件是在设计时创建的,并且能够在没有演示者的情况下运行(没有呈现行为)。

  3. 复合树中每个用户控件的一个演示者。所有演示者通过更高级的控制器类松散耦合。控制器类负责构建主持人,接线并协调事件。

尽管是最后的解决方案对我来说(因为它的复杂性),我认为最后一个选择是你正在寻找的解决方案。

Although it is a solution of last resort for me (because of its complexity), I think that the last option is the solution that you are looking for.

这篇关于MVP和UserControls和调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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