Thursday, February 07, 2013

Intro to MVVM in four easy episodes....

CodeProject - MVVM # Episode 1 (2, 3 & 4)

Introduction

MVVM seems, to me, to be the best way to develop applications that are both flexible - allowing changes to the GUI without complex rewrites, and allowing testing of the client logic without needing to resort to complex macros.

In this series of articles, I will present a small application in WPF, using an enhanced MVV pattern that I'm calling MVVM#.

So, what's different about my implementation? The main things are:

  • Message Tracking: When a message is sent, we now know if it has been handled.
  • Cancellable messages: A ViewModel can stop the message being sent further down the chain.
  • Easy Peasy Modal Dialog windows
  • No 'Main window': Everything is a View.
  • Use of a Controller: The Controller controls the application.
  • Easy to use Design Time Data for 'Blendability'
  • Use of ViewData for binding data to a View, as well as a ViewModel to bind behaviour to a view.

In this article, I introduce the topics, and ideas, and explain some of the differences.

In the second article, I'll show the way I set up any project using MVVM#, creating the base classes ready to begin the application specific development.

In the third article, I'll add sufficient meat to the bones created in article 2 to give us a running application, albeit one that doesn't do too much.

In the fourth article, I'll finish off the application to show a (small) but functioning application demonstrating some of the functions available.

Background

I've been looking at MVVM for a while now, without the opportunity to develop real applications using the pattern. I've downloaded and looked at most of the various frameworks, and even understood a few! But I don't like using a framework when I am learning something new - I want to understand the subject from the ground up. So I started playing, developing my own application using MVVM, and re-engineering to surmount the many obstacles I encountered.

In this article, I will describe some of the thought processes that drove me to extend the MVVM pattern, and introduce that pattern.

In the next article in this series, I will walk through developing an application from scratch, in VS2010 using C#, to implement this pattern.

Points of Interest

Man! It's a minefield out there!

There are so many articles, written by the extremely knowledgeable through to the novices, and it is really hard to sort the wheat from the chaff. Debts are due to the WPF Disciples in general, Josh and Marlon in particular, and especially Pete Hanlon who has responded to my often cryptic questions on CodeProject with never a groan! Thanks also go to any of the many people out there in etherland who have helped me, knowingly or not, to develop this series. Isn't it amazing how much free help there is out there? Hopefully, this series will help me give a little back.

..."

If you're trying to wrap your head around MVVM, this article series might help a bit. It's one mans implementation of MVVM, but it sounds like he's "been there, done that" and the article reflects some real world lessons learned. The thing with MVVM is that there seems to be about a billion ways to do it, and until there's an official implementation/guidance in the box,. there's going to continue to be. And while that's kind of neat, it's also a major pain in the butt when you're trying to get up speed on it ...

Anyway, this series provides one of the billion ways. And if this works for you, then you can ignore the other 999,999,999 for now... :)

No comments: