Using MVP pattern

Sep 25, 2007 at 4:13 PM
Beginning of August I started playing with the MVP pattern, from this article over at codeproject.

I'm pretty intrigued by this, as while it causes the code to be a bit harder to read at first, because of the three levels you have to look at, the end result has been something much easier to develop with. So I'm putting things back together using this new architecture, and maybe I'll be done this week.

The codeproject article is a better explanation, but what makes MVP interesting is that you really break down the app from the UI and the backend workings. The UI, or in this case an ASCX user control implements an interface which defines several events and properties... this is the view. You then attach a presenter at runtime to your control, where the presenter handles the backend functionality. The presenter sets and gets information on the view using the properties on the view, it then fires events which are handled by the view.

What's interesting, is I realized I had tried to do something like this before, only I was having my controls derive from a abstract class, and then I was handling the manipulation from the aspx page. This technique of placing the presenter in it's own code file does a much better job of abstracting out the functionality. And theorectically, now the presenter can be unit tested.

Unit testing is what I start experimenting with tonight.