22 Oct 2011
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
○MVVM for Silverlight http://msdn.microsoft.com/en-us/magazine/dd458800.aspx
Prism