Tuesday, July 25, 2006

MVP - The Resurrection

In my previous post I alluded to a poor article about MVP on the Microsoft Patterns & Practices site that seems to misunderstand some of the key concepts underlying this pattern.

However redemption for Microsfot is at hand in an article by Jean-Paul Boodhoo in the August 2006 issue of MSDN Magazine. However you can see that the result of proper separation is a whole lot of code (14 projects for a trivial 1 page aspx!)

If you have been paying attention then you wil know that MVP has, at least according to Martin Folwer, been retired and replaced by two alternatives - Supervising Controller and Passive View. As it's name suggests the 2nd of these is the most pure (extreme) version where the View is no longer responsible for updating itself from the Model. Jean-Paul's article falls into this category. The question that you will need to ask yourself next time you are creating an aspx page is how much is too much in a View.


If you have ever tried to unit test an aspx page then you've probably discovered that the tight coupling with the ASP.NET runtime makes this task difficult if not impossible. Of course there are other options such as Selenium or NUnitAsp but these are really integration testing tools - the tests are several orders of magnitude slower to run and time consuming to write and maintain.

The answer was the Model View Presenter (MVP) pattern. This is a variation on the classic Model View Controller pattern with a paper thin View layer (note to Microsoft - the code-behind is the View and NOT the Controller!). An excellent article on how to implement MVP in ASP.NET was written by Bill McCafferty.

However MVP is dead. I know this because Martin Fowler says so. Of course it's not really dead, it's simply been split into the Passive View and Supervising Controller/Presenter patterns. I'm still digesting the implicatioins of this change and will be sure to comment more on it later.