The Practical MVVM Manifesto outlines a set of principles a XAML based MVVM implementation should strive to follow. As the intent is to fulfill all of these goals, they are not listed in any particular order. As you will see, these principles work together to form a more complex whole. With few exceptions, failing one principle may hinder the viability of the entire implementation.
Each View should have a single ViewModel and a ViewModel should only service a single View.
This principle limits confusion and frustration and over time is easier to maintain. I recommend that your pattern follow a simple naming convention to ensure that Views and ViewModels are syntactically related: i.e. MainWindow's ViewModel should be named MainWindowViewModel. This convention is reinforced by the Blendability Principle.
The ViewModel should support Expression Blend.
Expression Blend is the premier UI and UX design tool for XAML based applications. An MVVM implementation should not preclude the effective use of Blend. To ensure support for Blend, the ViewModel class must have a public parameterless constructor and the DataContext of the View should be defined in XAML. This principle promotes Blend's ability to manage data binding. An instance of MainWindowViewModel will be named MainWindowViewModelDataSource.
This principle is also required to support the Designability Principle.
The ViewModel should supply Design Time Data.
XAML based applications should make heavy use of Data Binding. An unfortunate side effect of this is that once binding is applied, it can be difficult to visualize controls in design tools such as Expression Blend and Visual Studio's Cider. By following the Blendability Principle, an instance of the ViewModel is created at design time. This makes it possible for an MVVM architecture to overcome this limitation by providing mock instances of the ViewModel or its data elements at design time.
The ViewModel and Models should be testable.
Unit testing is an increasingly important aspect of software development practices. Since XAML based applications provide an almost complete separation of concerns it is certainly feasible to architect ViewModels so that they can be Unit Tested. ViewModels and Models should be architected in such a fashion as to support Unit Testing while adhering to the other principles listed in this Manifesto.
Joel Cochran is an Expression Blend MVP, INETA Community Champion, and author of Expression Blend in Action by Manning Publications.
All works and contents herein Copyright © 2011.