MVC vs MVVM
People think MVVM is just MVC with a new name, since both split screen code into three parts. In MVC, a controller takes the user's input and picks what the view shows. In MVVM, a view model holds the screen's state, and the view binds to it. Changes then flow both ways by themselves. The view model never touches the view, so it is easy to test.
Model-View-Controller (MVC)
Splits an app in three: data, screens and the code that links them.
Model-View-Controller, or MVC, splits an app into three parts. The model holds the data and the rules. The view shows the data to the user. The controller takes what the user does, updates the model and picks a view. The idea dates from the late 1970s and is still used by many web frameworks today.
Model-View-ViewModel (MVVM)
A way to split screen code into three parts. Data, the view, and a view model.
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.
In one line
- Model-View-Controller (MVC)
- Splits an app in three: data, screens and the code that links them.
- Model-View-ViewModel (MVVM)
- A way to split screen code into three parts. Data, the view, and a view model.