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

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

问题描述

我在尝试了解一些 MVP 的东西时很开心,因为它与用户控件有关.我正在使用 .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 应用程序的一部分(它的视图和关联的演示者等).Presenter 总是先启动,然后启动 Model(s),然后是 View(s).View 构建其 UI,其中一部分将用于 NEW 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 是表单控件集合的一部分,也不应该知道.

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 视图(表单)的开发人员应该能够从工具箱中选择一个用户控件并将其放在表单上.

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.

那么,继续我的问题.首先,我上面的假设是否正确?有点误导?弄乱?你在想什么?

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 View它的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.

我经常使用被动视图模式实现复合用户控件和表单.基本上有 3 种不同的配置:

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天全站免登陆