简体   繁体   English

Model-View-Presenter模式中的Presenter是否应该在视图上处理多个“ UI”元素?

[英]Should a Presenter in the Model-View-Presenter pattern handle multiple 'UI' elements on a View?

I am implementing a Diagram/Flow-Chart type designer using a Model-View-Presenter (MVP) pattern in WPF. 我正在使用WPF中的Model-View-Presenter(MVP)模式实现图/流程图类型设计器。

I have often though of this pattern (and some of the others such as Passive View and MVVM) as high level architectures that fail to address some of the complexity involved in rich UIs (here come the SO trolls). 我经常将这种模式(以及其他一些模式,例如Passive View和MVVM)视为高级架构,无法解决富UI所涉及的某些复杂性(SO巨魔在这里)。

In my particular instance, I have a UI which resembles the following mockup: 在我的特定实例中,我有一个类似于以下模型的UI:

在此处输入图片说明

I have made the choice to use Presenter objects for each element which requires presentation logic on the designer. 我已经选择对每个元素都使用Presenter对象,这需要设计器上的演示逻辑。 This has left me with the following designers thus far. 到目前为止,这已使我离开了以下设计师。

DesignerPresenter ControlPresenter ControlOverlayPresenter ConnectionPresenter ConnectionPointPresenter OverlayPresenter DesignerPresenter ControlPresenter ControlOverlayPresenter ConnectionPresenter ConnectionPointPresenter OverlayPresenter

The reason I have implemented each of these is because each of them needs to handle presentation logic and communicate its actions to the business/domain tier separately in order to avoid bloat (IMO). 之所以实现这些功能,是因为它们每个都需要处理表示逻辑并将其动作分别传达给业务/域层,以避免膨胀(IMO)。

The only other way I would see doing this is if there was one presenter that handles all this presentation logic which seems like it would get out of control very quickly. 我看到的唯一的另一种方式是,如果有一个演示者来处理所有这些演示逻辑,那似乎很快就会失去控制。

My question(s) are as follows: 我的问题如下:

  1. Is it common to see presenter provided for each UI element on the screen such as I am doing in order to allow for separation of the presentation logic? 像我正在做的那样,为了允许分离演示逻辑,在屏幕上看到为每个UI元素提供演示者是否很常见?
  2. Some of the presenters that are created are logically child presenters (The ControlPresenter is a child presenter of the DesignerPresenter) Is this normal? 从逻辑上讲,创建的一些演示者是子演示者(ControlPresenter是DesignerPresenter的子演示者)这正常吗?
  3. Is this in alignment with another pattern that makes more sense? 这是否与另一个更有意义的模式保持一致?

I never used the MVP but I'm really comfortable with the MVVM pattern and if I replace the word Presenter with ViewModel the design fits with what I would really do. 我从没使用过MVP,但是我对MVVM模式非常满意,如果我将Viewer替换为Presenter一词,那么设计就可以满足我的实际需求。

It is completely normal that the DesignerPresenter has an ObservableCollection of ControlPresenter and that the ControlPresenter contains an ObservableCollection of ConnectionPresenter. DesignerPresenter具有ControlPresenter的ObservableCollection,并且ControlPresenter包含ConnectionPresenter的ObservableCollection是完全正常的。 The ConnectionPresenter will probably have two ConnectionPointPresenter as well. ConnectionPresenter可能也将具有两个ConnectionPointPresenter。

The overall design seems ok but there are probably other similar architectures that would fit too. 总体设计似乎还可以,但可能还有其他类似的体系结构也适用。 IMHO maybe there is too much separation. 恕我直言,也许有太多的分离。 Makes sense to separate a connection and the connection points? 分离连接和连接点是否有意义?

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

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