Model-view-viewmodel (MVVM)
Model-view-viewmodel (MVVM) is an architectural pattern, commonly used to implement user interfaces, that divides a system into three interconnected parts. The model manages the data and domain logic of the system and depends on neither the view nor the view model. The view is the visible user interface, or some part of it. The view-model sits between the two, holding the UI’s presentation logic. The view-model may depend on the model, but never on the view.
MVVM is a sibling of model-view-controller (MVC) and model-view-update (MVU). Where MVC’s controller actively mediates input, MVVM’s view-model is passive and relies on data binding to stay in sync with the view. And where MVU keeps state in a single immutable model, MVVM’s view-model is free to hold its own mutable UI state.
The view-model is what distinguishes MVVM from its siblings. It exposes the model’s data and behavior in a form the view can bind to directly, typically through a two-way data binding mechanism, so that changes in the view-model update the view automatically and vice versa. This binding is what lets MVVM keep the view free of logic, since the view-model – not the view – decides what to display and how to react to input.