开发者

Model-View-Presenter: Why is model static?

开发者 https://www.devze.com 2023-04-04 13:31 出处:网络
I\'ve been attempting to fully understand the Model View Presenter pattern as it applies to C#.I have one question I can\'t wrap my head around.

I've been attempting to fully understand the Model View Presenter pattern as it applies to C#. I have one question I can't wrap my head around.

In many examples, I noticed that model is defined as static and is constructed in the Presenter base class (often a generic class).

How does one have multiple model classes in that case? From my understanding, every presenter created will only be able to reference a single model class.

The example I'm looking at now can be found here: http://wesaday.files.wordpress.com/2009/01/finalzip.doc (rename to .zip). It's from this tutorial: http://wesaday.wordpress.com/2009/01/30/winform-model-view-presenter-part-v-the-view/

The guess the overall issue I'm having is seeing how examples like the one above adapt to a working application with mult开发者_运维问答iple views/presenters/models.


This is presumably just a simplification in order to avoid incorporating a complete IoC implementation in the sample. An MVP triad is usually represented by stand-alone (i.e.: not static, singleton, or otherwise shared) instances at runtime. In some exceptional cases, a model may be a shared instance, but this is usually the exception rather than the rule, and it's generally only the case for read-only forms or controls.

0

精彩评论

暂无评论...
验证码 换一张
取 消