Monday, May 07, 2012
« Should I learn Silverlight? Objective C?... | Main | Set rich text into RichTextBlock control... »

There are three fairly popular presentation layer design patterns that I collectively call the “M” patterns: MVC, MVP, and MVVM. This is because they all have an “M” standing for “Model”, plus some other constructs.

The thing with all of these “M” patterns is that for typical developers the patterns are useless without a framework. Using the patterns without a framework almost always leads to confusion, complication, high costs, frustration, and ultimately despair.

These are just patterns after all, not implementations. And they are big, complex patterns that include quite a few concepts that must work together correctly to enable success.

You can’t sew a fancy dress just because you have a pattern. You need appropriate tools, knowledge, and experience. The same is true with these complex “M” patterns.

And if you want to repeat the process of sewing a fancy dress over and over again (efficiently), you need specialized tooling for this purpose. In software terms this is a framework.

Trying to do something like MVVM without a framework is a huge amount of work. Tons of duplicate code, reinventing the wheel, and retraining people to think differently.

At least with a framework you avoid the duplicate code and hopefully don’t have to reinvent the wheel – allowing you to focus on retraining people. The retraining part is generally unavoidable, but a framework provides plumbing code and structure, making the process easier.

You might ask yourself why the MVC pattern only became popular in ASP.NET a few short years ago. The pattern has existed since (at least) the mid-1990’s, and yet few people used it, and even fewer used it successfully. This includes people on other platforms too, at least up to the point that those platforms included well-implemented MVC frameworks.

Strangely, MVC only started to become mainstream in the Microsoft world when ASP.NET MVC showed up. This is a comprehensive framework with tooling integrated into Visual Studio. As a result. typical developers can just build models, views, and controllers. Prior to that point they also had to build everything the MVC framework does – which is a lot of code. And not just a lot of code, but code that has absolutely nothing to do with business value, and only relates to implementation of the pattern itself.

We’re in the same situation today with MVVM in WPF, Silverlight, Windows Phone, and Windows Runtime (WinRT in Windows 8). If you want to do MVVM without a framework, you will have to build everything a framework would do – which is a lot of code that provides absolutely no direct business value.

Typical developers really do want to focus on building models, views, and viewmodels. They don’t want to have to build weak reference based event routers, navigation models, view abstractions, and all the other things a framework must do. In fact, most developers probably can’t build those things, because they aren’t platform/framework wonks. It takes a special kind of passion (or craziness) to learn the deep, highly specialized techniques and tricks necessary to build a framework like this.

What I really wish would happen, is for Microsoft to build an MVVM framework comparable to ASP.NET MVC. Embed it into the .NET/XAML support for WinRT/Metro, and include tooling in VS so we can right-click and add views and viewmodels. Ideally this would be an open, iterative process like ASP.NET MVC has been – so after a few years the framework reflects the smartest thoughts from Microsoft and from the community at large.

In the meantime, Caliburn Micro appears to be the best MVVM framework out there – certainly the most widely used. Probably followed by various implementations using PRISM, and then MVVM Light, and some others.

Monday, May 07, 2012 3:11:10 PM (Central Standard Time, UTC-06:00)
I think knockout.js should be up there in the list of "best MVVM frameworks" because it does an amazing job for client side web programming.
Patrick
Monday, May 07, 2012 3:25:07 PM (Central Standard Time, UTC-06:00)
I think you're mostly right...but I think that understanding the pattern is more important than the pattern. I used to do a MVVM talk where I built most everything by hand so people could see the moving parts...which makes picking a framework much easier. Unfortunately, in many shops someone picks the framework based on the popularity; not the fit to the development project.

For me the frameworks tend to be recommended in this order:

- MVVM Light: Requires the least 'do it my way' than the other two listed here. Small and consise which has great merits.
- Caliburn Micro: Most complete but more complex for simple scenarios. Probably not a candiate for smallish projects IMO (e.g. mobile)
- Prism: Good disconnected framework and if you're trying to interoperate or be complete a "Built-by-MS", this is a good strategy. Good interop with EntLib and other PnP projects. But not my first choice.

(Almost wrote my own post, but thought this was easier ;)
Monday, May 07, 2012 11:38:13 PM (Central Standard Time, UTC-06:00)
If you're interested in something similar to ASP.NET MVC for WPF apps I think that Magellan might be of interest to you.

http://code.google.com/p/magellan-framework/
Aidan Morgan
Tuesday, May 08, 2012 5:51:01 AM (Central Standard Time, UTC-06:00)
Nice article! I agree with this for new project.

What im struggling with, is that the project im working on has been around since silverlight 1.
There has been alot of different developers over time and the codebase is messy, to say the least.

Rewriting is not an option. What i do is to gradually replace parts. Whenever there is a component that needs rework, i rewrite it using only the very very basic of mvvm. Bringing in a full framwork wont really help me at this point. What i hope and strive for it to get the management to "see the light" and be currious on the reasons behind big increases in productivity. I'm a consultat with about 6 months on the project now.

But yes, i wouldnt try to build myself an event router but i do believe in small baby steps starting small, bring in mvvm piece by piece with lots of legacy code.

Any thought on that?
Sven
Tuesday, May 08, 2012 4:42:45 PM (Central Standard Time, UTC-06:00)
yet another reason to ditch XAML in favor ASP.NET MVC!

just kidding... sorry i could not help myself
GA
Wednesday, May 09, 2012 10:27:56 AM (Central Standard Time, UTC-06:00)
I was very surprised you endorsed Caliburn as the "best". Perhaps best for you? In my experience there's no way I would make that recommendation about *any* MVVM framework because they are all so different and there is *no* objectively "best" framework. I chose Prism after thoroughly examining every MVVM framework out there I could get info on including Caliburn.

Some are more thorough than others and support more features but often they might be features you don't need so it's not that easy.
JohnC
Thursday, May 10, 2012 1:25:45 PM (Central Standard Time, UTC-06:00)
Have you ever tried the Catel MVVM Framework?
I find it surprisingly easy and feature rich.
Until now I used Bxf for my spike solutions.
After migrating to Catel, the only thing I am curious about is which ViewModelBase class I should use.
The one contained within Catel works perfectly with Catel (how surprising!).
But the one from Csla.Xaml features the Csla specific methods like BeginRefresh or the CanXyz methods and the builtin model property...
Maybe I should derive a class from Catel.ViewModelBase and reinvent the features from Csla.Xaml.ViewModelBase<T> ?
Any suggestions?
Alexander Becker
Monday, May 14, 2012 1:29:21 PM (Central Standard Time, UTC-06:00)
Rocky,

I'm certain you have enough plates spinning at any one time, but will Bxf receive any further attention? I find it to be a nice lightweight MVVM framework that I use as a base while developing my business,data layer and view models. At a more advanced stage I replace that project with Prism, but Bxf is so much lighter/easier to do initial dev with.

Ed
Ed Mathias
Monday, May 28, 2012 11:58:08 AM (Central Standard Time, UTC-06:00)
Based purely on number of downloads, I believe that MVVM Light (disclaimer: this is my framework ;) is more widely used than Caliburn.Micro. I recently celebrated 120'000 downloads from Codeplex and Nuget.

That said there are no doubts that Caliburn is an excellent framework too.

Cheers
Laurent
Comments are closed.