Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model-View-Presenter: Why is model static?

Tags:

c#

wpf

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 multiple views/presenters/models.

like image 472
halohunter Avatar asked Sep 12 '11 17:09

halohunter


1 Answers

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.

like image 76
Nicole Calinoiu Avatar answered Nov 15 '22 05:11

Nicole Calinoiu