Model–view–viewmodel
Appearance
Overview
The model-view-viewmodel pattern is a specialization of the Presentation Model (PM) design pattern introduced by Martin Fowler [1] specific for the Windows Presentation Foundation. The design pattern is similar to the Model View Controller and Model View Presenter design patterns.
The problems this design pattern tries to address include:
- (Unit) testability of all code
- Seperation of code and presentation
The pattern uses the ICommand[2] interface extensively to handle events like Button clicks to avoid writing "code behind", which would couple the presentation layer with the code.
Additionally use the IServiceProvider[3] interface to handle services provided by UI snippets like dialogs.
Pattern description
- The model consists of the data model as well as the business logic, no UI specific data or code
- The view is pure presentation logic
- The ViewModel (Model of a View) is the glue that binds the model to the view, an abstract version of the view. The ViewModel is also a specialization of the Model in the sense that it presents the model data in a bindable (in the WPF sense) form by implementing the [4] interface for example.
Notes
External References
- Josh Smith. "WPF Apps With The Model-View-ViewModel Design Pattern". MSDN Magazine.
- John Gossman. "Tales from the smart client".