Alex Mueller on Software and Technology 
Sunday, January 07, 2007

Billy McCafferty wrote a great article "Model View Presenter with ASP.NET." In it, he provides an approach to using MVP with ASP.NET, where we have views, presenters, and models, but we also have a view initializer. In ASP.NET, the view initializer is the ASPX page, and the views are the ASCX user controls.

The View Initializer (VI) knows about the View, the Presenter, and the Model. It is responsible for initializing views and page redirections. The VI declares the view(s) that implement their interfaces. The VI creates the Presenter, passing into it the view and the model, if needed. After passing the view to the presenter, the VI then needs to initialize the view (InitView()) to complete the MVP cycle.

Martin Fowler wrote, "Many people find that testing GUIs to be somewhere between tough and impossible. This is largely because UIs are tightly coupled into the overall UI environment and difficult to tease apart and test in pieces." As a result of this, I tend to lean towards using Passive View and the Humble Object approach when using MVP.

It is difficult to test views, and this is why it is important to delegate as much behavior to the presenter to make the view as dumb as possible. At the same time, it also becomes important to use interfaces for views so we can properly use them in unit tests and acceptance tests. As a result of this, I have been implementing MVP in projects recently, leveraging its testability.

MVP seems like a ton of extra work, and this can be a true statement. As we become more familiar, implementing it becomes easier. As we write our unit tests, we gain that return on investment.

Do not bother using MVP if you are not going to write unit tests. MVP promotes testability. If you are not taking advantage of this, then MVP is just extra work.

Read Billy's article, download his sample project, and write your own sample. MVP is a great design for ASP.NET applications.

Sunday, January 07, 2007 10:22:07 PM (Mountain Standard Time, UTC-07:00) | Comments [0] | Frameworks/Patterns#
MuellerDesigns.net
Search
On This Page
The Split Personality of the Tester/Developer
Cross Site Scripting (XSS)
Creating files with FSUTIL
PowerShell Management Library for Hyper-V
Installing Windows 7
Installing Linux in Hyper-V
Internet Explorer 8 Release Candidate 1
PowerShell Documentation
Automate Daily Tasks with PowerShell
SketchPath XPath Editor
Software Testing - Revisited
Architecting Buildings and Software
NBCOlympics.com with Silverlight
Marker Interfaces and C# Attributes
Most Popular
JavaScript ReplaceAll Functionality
What is polymorphism?
What is composition?
Sorting with IComparable and IComparer
Applying the Observer Pattern in ASP.NET
MVP in ASP.NET
What is abstraction?
What is encapsulation?
What is a class?
What is inheritance?
Authentication in ASP.NET
Calendar Controls
XPathNavigator.CheckValidity new for 2.0
SQL Server 2005 Connection Issues
Auto-attach to process '[####] aspnet_wp.exe' on m...
What is an object?
FreeTextBox
VMWare and VPC
An Example of Reflection using C#
Changing File Ownership In Vista and Longhorn
Archive
Links
Categories
My Local Blog Map
Blogroll
About
Powered by:

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
MuellerDesigns.net

Sign In

Help Those In Need
The Hunger Site
Ronald McDonald House Charities (RMHC) of Western Washington & Alaska