Model-View-Presenter (MVP) question
- From: kaspar.thommen@xxxxxxxxx
- Date: 24 Nov 2005 06:24:00 -0800
Hi there,
I just read the MVP article on
http://www.martinfowler.com/eaaDev/ModelViewPresenter.html. While the
given example nicely demonstrates the intent of MVP, I have trouble
using it for more complex things. Currently, I'm developing a project
to which, at a first glance, the MVP pattern can easily be applied. I
want to achieve independence of the View because the application is
supposed to run as rich client, as web app and maybe also as mobile
app.
A simplified UML diagram of the project looks like this.
View <--> Presenter ---> Model
This structure is similar to the one of Martin Fowler: A Model
representing some business data, a presenter which gets data from the
Model and presents it in the View, and a View that directs user input
to the Presenter. So far so good.
However, in my case, I have to do user input data validation. Assume we
are presenting customer data which the user can modify. If I press the
"Next Customer" button in the View, I first want to prompt the user to
either save or not save the modification before presenting the next
customer's data.
The question is now: Does the Presenter class have to know this? In
other words: When I click "Next Customer", shall the Presenter class
already read customer data from the view and send it to the Model for
validation, or shall it just tell the Model "Hey, the user has clicked
'Next Customer' - now do whatever you want", which, in turn, makes the
Model ask the Presenter to get customer data from the View?
It all boils down to the question: Is the Model allowed to know about
the Presenter? I see the following pros and cons:
pros:
- The communication between Model and Presenter can be simplified.
- The Model can ask the Presenter to show dialogs to the user ("Do you
want to save the cusomer data modifications?") which would be hard to
do if the Model didn't know about the Presenter.
cons:
- The Presenter has domain knowledge, so if I change the Model, I may
have to change the Presenter too (e.g. if I suddenly decide NOT to
perform input data validation).
- The Model is couped witch the Presenter which makes testing more
difficult. I would have to write an IPresenter Interface, make
Presenter and MockPresenter implement it for testing
I would actually like to make the Model NOT know about the Presenter,
but this makes it for example hard to show any dialogs to the user
before performing some domain specific action (again, the "Do you want
to save the customer data modifications?" dialog).
Any help is appreciated.
Regards
Kaspar
.
- Follow-Ups:
- Re: Model-View-Presenter (MVP) question
- From: AndyW
- Re: Model-View-Presenter (MVP) question
- Prev by Date: Re: Decouple SQL queries from class in OOP design
- Next by Date: Re: Looking for a good book on object-oriented GUI programming
- Previous by thread: offtopic: looking for a name for a concept
- Next by thread: Re: Model-View-Presenter (MVP) question
- Index(es):