views:

67

answers:

1

I have a MVP (passive view) setup, and it is going quite well. 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."

In my MVP I have my model completely oblivious of a presenter, and communication from the model to the presenter is handled by events. I initialize my MVP in the view by calling the presenter ctor e.g. new Presenter(this, new Model()) (where this refers to the view).

My question is, should I make the model aware of a presenter such that it can invoke presenter logic directly instead of using events?

+4  A: 

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.

HTH,
Kent

Kent Boogaart
Then how can Martin Fowler even think of saying that the passive view has very little reliance on observer mechanisms? Perhaps he means mechanism that would tie the view to the model directly (through events e.g.)?
lejon
Because the presenter dictates to the passive view (whereas an active view requires less hand-holding, if you like). In other words, the passive view is not observing the presenter, but the presenter is observing the model (and dictating to the view accordingly).
Kent Boogaart