Friday, May 1, 2009

MVVM Resources

MVVM or M-V-VM is a new architecture like MVC and MVP ,which is more suitable for WPF and Silverlight which supports data binding .It stands for Model View ViewModel.Before reading further please have some idea in MVC (Model View Controller) and MVP(Model View Presenter) if you don’t have already.

Some links to MVC and MVP

MVC - The Official Microsoft ASP.NET Site
Design Patterns- Model View Presenter
Model View Presenter - Wikipedia, the free encyclopedia
http://www.codeproject.com/KB/architecture/ModelViewPresenter.aspx

What is M-V-VM

Model and View are same as in MVP and MVC.The only change is in the ViewModel. This effectively separates the model and view.Confused?Lets see what is this new View model ?

View model is a class which wraps data binding enabled view objects or properties and commands which drive the flow of the application.The properties contain what ever the view is supposed to display.These properties are designed based on the model.Commands are just WPF commands which implements the ICommand interface.They are executed by the user actions from the view.So they are normally associated with the buttons or other controls which implements ICommandSource interface.

Simply saying the view model loads the data which are to be displayed from model and displays through view by means of data binding.In the reverse direction it accepts user actions from view through commands and performs required actions on model.

In the ideal situation there should be no direct communication between view and the model.Everything should pass through the view-model.One more thing in ideal situation is views should not have a code behind.Have an image google using MVVM if you need a block diagram of this architecture.

Learning and designing MVVM architecture

Due to time limit ,here I am giving some links which describe MVVM in detail.Hope I can write more about implementation side later.At the first time you will feel that, this is very difficult to achieve.Scenarios such as ‘performing something on ListBox selection but it doesn't have a Command property which executes on selection’ and  ‘method to invoke a command on mouse over’ will come.But once you go through the below links you can find solutions for all these issues and go smoothly with MVVM.

Intro to MVVM by Josh Smith
THE MODEL-VIEW-VIEWMODEL (MVVM) DESIGN PATTERN FOR WPF

Using mediator pattern to implement communication among view models
[MVVM + Mediator + ACB = cool WPF App] – Intro « C# Disciples

Command invocation on any control any event
Applying Command Binding to any control and any event

Will be adding more as soon as I come across

No comments:

Post a Comment