MVVM separates the interface from the logic: the visual part knows nothing about data storage or network requests, and the details of controls never touch the logic. Data binding holds the relationships between the layers: when a value changes in one layer, it is updated in the layers bound to it as well.
Three layers
| Layer | What it is responsible for |
|---|---|
| Model | the data and the rules for processing it: access to the database, network APIs and the cache; knows nothing about the view |
| View | what the user sees: windows, pages, controls; describes appearance only |
| ViewModel | the view state and commands: takes data from the model and presents it in a form convenient for display |
The view and the view model are connected by data binding, so changing a field in the view model changes the text on screen without any update code, while user actions invoke view model commands. The view model also holds view state that markup cannot express: the selected item, view or edit mode. A screen usually has its own view model, and the dependency runs from the view to the view model: the view model knows nothing about the specific screen.
A binding example
<Label Text="{Binding UserName}" /><Button Text="Load" Command="{Binding LoadCommand}" />Where the term comes from
John Gossman, a Microsoft architect working on WPF, described the MVVM pattern in a blog post in October 2005. He called the pattern a variety of MVC for modern interface platforms, where a designer draws the view in a declarative language such as XAML while a developer writes the logic. The pattern’s second pillar is the shared data binding mechanism — without it the view model has nothing to bind to the view.
Where it is used
- Microsoft applications: WPF, .NET MAUI — the documentation describes MVVM as a way to separate the interface from the logic.
- Mobile development: on Android, the Jetpack ViewModel stores the screen’s state and survives its rotation; a similar approach is used in SwiftUI.
- The web: Knockout is built around MVVM, and an early version of Vue described itself as the pattern’s view model layer.
Sources
the term is written from these pages- John Gossman — Introduction to Model/View/ViewModel pattern for building WPF apps (2005)learn.microsoft.com/en-us/archive/blogs/johngossman/introduction-to-modelviewviewmodel-pattern-for-building-wpf-apps(opens in a new tab)
- Microsoft Learn — Model-View-ViewModel (MVVM) в .NET MAUIlearn.microsoft.com/en-us/dotnet/architecture/maui/mvvm(opens in a new tab)
- Android Developers — ViewModeldeveloper.android.com/topic/libraries/architecture/viewmodel(opens in a new tab)
Verified 8 Nov