简体   繁体   English

关于模型 - 视图 - 演示者(C#)的一般性问题,模型应该知道演示者吗?

[英]A general question on model-view-presenter (C#), should the model know the presenter?

I have a MVP (passive view) setup, and it is going quite well. 我有一个MVP(被动视图)设置,它进展顺利。 I recently read Martin Fowlers description of this (http://martinfowler.com/eaaDev/PassiveScreen.html) and he writes "Another advantage that Passive View is a very explicit mechanism. There's very little reliance on Observer mechanisms or declarative mappings." 我最近阅读了Martin Fowlers对此的描述(http://martinfowler.com/eaaDev/PassiveScreen.html),他写道“Passive View是一个非常明确的机制的另一个优点。很少依赖Observer机制或声明性映射。”

In my MVP I have my model completely oblivious of a presenter, and communication from the model to the presenter is handled by events. 在我的MVP中,我的模型完全忘记了演示者,从模型到演示者的通信由事件处理。 I initialize my MVP in the view by calling the presenter ctor eg new Presenter(this, new Model()) (where this refers to the view). 我通过调用presenter ctor来初始化我的MVP,例如新的Presenter(这个,新的Model())(这指的是视图)。

My question is, should I make the model aware of a presenter such that it can invoke presenter logic directly instead of using events? 我的问题是,我应该让模型知道一个演示者,以便它可以直接调用演示者逻辑而不是使用事件吗?

No, you shouldn't. 不,你不应该。 If you did, your model would be tightly coupled with your presentation layer, making it useless outside of that context. 如果您这样做,您的模型将与您的表示层紧密结合,使其在该上下文之外无用。 Moreover, testing, debugging and maintaining your model layer would become more problematic. 此外,测试,调试和维护模型层会变得更加困难。

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

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