Friday, February 24, 2012

WinForms MVP! (No, not that kind of MVP, MVP as in Model View Presenter...)

Moot Points - WinForms and MVP: Making a testable application

"With modern frameworks available that were built with loose coupling and separation of concerns in mind, working in WinForms may seem like a testability wasteland. But there are times when the options of WPF with MVVM or MVC on the web are not available, and you’re stuck with WinForms. But fear not, the Mode-View-Presenter pattern is here to save the day!

If you are not familiar with the MVP pattern, the idea is that you have a presenter, which handles all the interactions between the user and the model. The presenter “Talks” to the UI through an abstraction. There are a couple ways of doing the MVP pattern. I’m going to explore the Passive View style, meaning all logic is taken out of the view and moved into the presenter. I’m not going to go into differences in the styles, but if you’re interested, Martin Fowler has in depth descriptions of the Passive View, and Supervising Controller patterns, which are both derivatives of MVP.

I’m going to do a walkthrough for creating a simple MVP application. We need a premise for our demo. I’ll go with something simple, an application that organizes notes. Here our note will be a bit of textual data with a title. Lets implement it.

...

image..."

I'll say it, WinForms can rock! THERE! HA! Said it!

Seriously, I still find it so much easier to use WinForms when knocking out a test harness, PoC form, etc. Some of the simple things are just so much easier...  I know, I know, they are "dead" and have no future, but still sometimes they really are the right tool for the job.

Now marry that up with a good model like MVP...

No comments: