Skip to content
BENIBIX Learn

Model-View-ViewModel (MVVM)

Development🏗️ ArchitectureArchitecture Styles

Also known as MVVM, MVVM Pattern, View Model

A way to split screen code into three parts. Data, the view, and a view model.

Think of it like

It is like a scoreboard. When the score changes, the board shows it by itself.

Example

Emma's login screen binds its button to a SignIn command on the view model. She tests that command with no screen at all.

Why it matters

The view model can be tested without a screen. Designers can change the look without touching the logic.

Definition

MVVM is a way to split an app's screen code into three parts. The model holds the data and the rules. The view is what the user sees, and it holds no logic. The view model sits between them and holds the screen's state and actions. The view is tied to the view model by data binding, so a change in one shows up in the other by itself. It is common in .NET apps.
The view binds to the view model, and the view model talks to the model.

Common mistake

Putting logic in the view's own code file. Then it cannot be tested on its own, which was the point of MVVM.

Key takeaways

  1. 1
    Model. Data and rules.
  2. 2
    View. Only what is seen.
  3. 3
    Data binding. Changes flow both ways.

Compare