Skip navigation

I remember helping a developer who was attempting to transition from C to C++. Because valid C is valid C++, it was difficult to get the point across to him that — even though it worked — it wasn’t necessarily the best way to do things. It takes a concentrated effort for someone to unlearn bad habits.

For an example look at Winforms programming. It is dead simple to drag a few controls onto a form and wire it up to perform business logic on a button click. I must confess I’ve done this myself, even as recently as last year (oh wait it’s 2008 now make that the year before last). It took me struggling with WPF to realize that even though it "worked" that was not the best way to wire up my UI (in all but the simplest of cases). I decided to explore the benefits of the Model-View-Controller Pattern (or MVC for short) for my application development. I knew of this design pattern’s existence but had never bothered to implement it explicitly in my development. As I got my feet wet with using MVC for my WPF UIs, I started noticing a lot of benefits.

Actually let me correct myself. I didn’t consciously decide when I first started coding in this manner that I was going to use the MVC pattern. I just decided to remove the logic of deciding what controls were enabled, how to initialize the UI, and how to validate the data entered into the form (among other concerns) away from the Window/UserControl and into a helper class that worked with the UI while shielding it from the intricacies of how the system works.

Once I looked at what I had done, I finally realized that I had implemented a variation on the MVC pattern. I had read some of Dan Crevier’s blog postings regarding what he called the Model – View – ViewModel, or MVVM, pattern (itself a refinement of the MVP pattern) prior to this so I guess it had laid dormant in my subconscious until I needed it.

I have come to realize that going from basic "Forms and Controls" (as Martin Fowler calls it) UI development to MVC is a paradigm shift on the magnitude of going from procedural development to object-oriented development (e.g. C to C++). Although the same development techniques that make Winforms (and VB before it) development so approachable still "work" with WPF, the framework really shines when you move to an MVC architecture for your UI. Once you grok this concept, you’ll find that you’ll hesitate to write even simple applications without using it.



  1. I too was programming a lot of my WPF code in the "WinForms" way.  I have always made ui controls for everything, but MVVM or DMVVM or OMGWTF wasn\’t making much sense until the last couple months.
    Another thing I also have found is that making all controls lookless is a hard habit, but the dicipline is well worth it.

  2. I would say that one of the biggest things about WPF is the
    fact that it tries to remove all UI logic from your code! In fact if we look at
    Model View ViewModel, it is really obvious how WPF helps us removing our UI

    Another way how one can immediately see the power of WPF is the fact that
    "Designers" now understand our code!!! Do designers know programming?
    HELL NO (well at least the designers I work with) But WPF is an intermediate

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: