With Microsoft WPF technology, a new pattern is born and is going to be called MVVM (Model View ViewModel). This pattern is an hybrid from the old MVC and the old MVP patterns. Why a new pattern for the presentation?
- First of all WPF technology is giving us a kind of technology that can completely change the approach to design and code the UI. With the VMMV we can completely design an agnostic UI that doesn’t know the Model we are going to pass to it.
- Recycle, I will show you in this tutorial how to simply convert a WPF application into a Silverlight app.
- Better delegation and better design for a real n-tier application. In this example we will use LinqToSQL and WPF to build a complete n-tier application with the VMMV.
- Something that I do not like, TESTING THE UI!! Yes we can test the UI with WPF and VMMV combination.
- Abstractation. Now the view can be really abstract and you can use just a generic.xaml file and then give a style template to your model.
This is the schema (in my opinion) on how it should work an application with WPF and the VMMV implementation:
- MODEL: anyone that has already worked on an n-tier application knows what it is. The model is the group of entities that will be exposed.
- VIEW: the view is the graphical code XAML used to generate the UI, nothing more then that.
- VIEWMODEL: the model for the view … or … the view for the model?! Anyway is a model of the view.
Before starting this tutorial I suggest you to download:
- Visual Studio 2008 SP1 and NET Framework 3.5 SP1
- The complete AdventureWork database template for SQL
- SQL Express 2008
The next tutorial will show you how to create a simple DAL layer with LinQtoSQL and how we can implement the Unit of Work pattern to build a simple but solid data layer for our application.