MVVM or MVP for Winforms?

July 31, 2010

MVVM (Model-View-ViewModel) pattern  is more suited for WPF, while MVP (Model-View-Presenter) pattern  is more suited for Winforms. MVVM offers more benefits than MVP. It might still be possible to make Winforms support MVVM.  Hence I was trying to find whether it is beneficial to use MVVM over MVP in a winforms Application. I have summarized my findings below.

MVVM is more loosely coupled than MVP. In MVP, the View implements an interface IView and the presenter uses this interface. Since each view is different, it makes less sense to make each view implement the same IView interface. We might end up creating separate interfaces and Presenters for each view. With MVVM the view is aware of the viewModel, and the viewModel is aware of the model (but not vise versa). This means that multiple views can use a ViewModel and multiple ViewModels can use a Model. Hence MVVM is loosely coupled than MVP.

MVP and MVVM

 

MVVM utilizes the features of WPF such as Data Binding, Commands, Data Templates. WPF (and Silverlight 2) features make MVVM a natural way to structure the application. This is not the case with Winforms.  Although Winforms supports databinding, you need to write some extra code to support two way data binding in Winforms by implementing INotifyPropertyChanged interface.  In the case of MVP, there is no need for two way data binding. The Presenter does the job of updating the view. You can also try creating a command manager for supporting Commands for MVVM, but it is much harder. Winforms do not support Data templates.  You can make Winforms support MVVM but you might not get all the benefits  of using MVVM in WPF.

If MVVM is properly used it is more testable than MVP.

The descision to use MVVM for Winforms is still up to you, based on your project needs.

Below are the few links I referred:

Niraj Bhatt on MVC vs. MVP vs. MVVM

Safe usage of INotifyPropertyChanged in MVVM scenarios

MVVM/Presentation Model With WinForms

MVVM for Winforms

MVC vs. MVP vs. MVVM