A Quick Intro to MVVM

A quick view to Model–View–X  Paradigm

  • Model-View-Controller (MVC) – 1979
  • Model-View-Presenter (MVP)
  • Presentation Model (PM) by Martin Fowler – 2004
  • Model-View-ViewModel by John Gossman – 2005
  • Prism 1.0 : Composite Application Guidance for WPF – Jul 2008
  • Prism 2.0 : Composite Application Guidance for WPF/Silverlight – Feb 2009

Data Binding in WPF and Silverlight

  • ž     Bind anything to anything
  • ž     Convert types within bindings
  •         Markup based language for expressing bindings

Model-View-Viewmodel pattern

Benefits of MVVM

  • Separation of Concerns
  • —Modularity
  • —Loose Coupling
  • žEmpower Designer
  • žTestability
  • žLess Code
  • žReuse to other Platforms

Shortcomings/Challenges

žNavigation / View Management
—Mediate Pattern – Driver, Controller, Presenter, View Manager
žException Handling
—Where to handle? View or ViewModel?
—Mediator, Events, Interfaces, DataBinding
žPossible Work around:
—Messenger – The Messenger class is a lightweight way of passing messages between various ViewModel objects who do not need to be aware of each other. This is based on the Mediator implementation created by Marlon Grech and Josh Smith, as seen on Marlon’s blog (http://mvvmfoundation.codeplex.com/ )
MVVM – Misconceptions
  • žNo Code-behind
  • žViews have to be DataTemplates
  • žConverters are not needed
  • žViewModel completely wraps Model
  • Only Big projects need to implement MVVM

Summary

žModel-View-ViewModel helps you and your customers to build better apps
  • —Unit testable
  • —Maintainable
  • —Better user experience
  • —Lower costs

 Resources

MVVM
   ○MVVM for WPF by John Gossman http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Prism