Tuesday, 19. September 2006
MVP revisited
In one of my early postings I introduced the model view presenter pattern as a feasible way to implement testable GUIs. Later I showed how you can easily apply the MVP style to Ajax applications using the JayJax framework.

In my description of MVP and presentation model I (over)simplified a bit about the many subtleties that come with those patterns. This was partly due to my endeavour for comprehensibility and partly due to my ignorance. When I revisited my postings a couple of weeks ago I found that one of my major sources for those GUI related patterns, namely Martin Fowler's Further Patterns of Enterprise Application Architecture had undergone a significant change in this respect.

To cut a long story short, Martin goes into quite some details about the history of MVP, its relation to other MVC derivates and MVP's two main flavours: The flavour I propose is basically the Passive View taken to extremes. This variant has been around for a while called the humble dialog box, a phrase coined by Michael Feathers in order to describe a GUI approach which lends itself well to test-driven development (TDD). Martin Fowler puts it like this:
The Humble Dialog Box [...] uses a presenter, but in a much deeper way than the original MVP. Not just does the presenter decide how to react to user events, it also handles the population of data in the UI widgets themselves. As a result the widgets no longer have, nor need, visibility to the model; they form a Passive View, manipulated by the presenter.
By the way, check out Michael Feathers' weblog which will give you many insights into the subtleties and strengths of test-driven development. Michael is one of the pioneers in the field and has challenged one of the most difficult aspects of TDD in a great book: Working Effectively with Legacy Code.