During the Architecture Best Practices session during last week’s Google I/O conference I was presented with an altogether unexpected statement: namely, that adopting the MVC pattern — in all its versions — is going to get you in trouble with a large GWT application.
Instead of MVC, the new Google Adwords UI (IIRC) team used an MVP (Model-View-Presenter) pattern which had several advantages over MVC: by building an application using an event bus to channel and handle all events you reduce dependencies between models and views (multiple PropertyChangeListeners, etc.), making the code simpler; it also makes it much easier to decouple the layers and introduce testing objects for easier testing of the code.
Here’s the typical MVC diagram:

This should be a familiar pattern for everyone; it’s the diagram we’ve seen in one form or another for the past decade (or more) as various GUI toolkits come and go and UI best practices are rediscovered.
Compare that with MVP:

Here you have a strong Presenter that moderates between the view and the model. Neither is updated without the Presenter being involved in some way.
In developing our internal framework we’ve adopted an MVC patterns for normal user interactions, but an MVP pattern for controlling the history and bookmarking aspects of the application. Like at least one other person at the session, we’ve all started slowly moving toward MVP but didn’t quite know what it was, only that it made sense. Having it blatantly presented to us directly by a member of the GWT team made quite an impression.
It turns out that if you search for “MVC v. MVP” a good many .Net articles appear, many from the last year and a half, so there’s a fair number of discussions and resources on the topic. That it’s only now “sinking in” to the GWT world isn’t too much of a surprise… the question is which frameworks will support it and are there any that already support it out of the box?
Links:
http://code.google.com/events/io/sessions/GoogleWebToolkitBestPractices.html
http://martinfowler.com/eaaDev/uiArchs.html
RSS - Posts
August 15, 2009 at 2:07 pm |
[...] gxt mvc – forget mvc use mvp [...]
August 31, 2009 at 5:09 am |
Oh I can’t wait until one of the huge kitchen sink frameworks pours a big carton of MVP into their big bag of assorted widgets and tools.