Skip to the workspace
Pebellslearn by building
Patterns & Design Principles  ›  Lesson

MVC, MVP and MVVM

MVC, MVP, MVVM 15 minMVC, MVP and MVVM all separate data and rules from what is shown on screen, and differ in which part handles input and how the view gets updated.

software architect / MVC, MVP and MVVM

Explore each scene at your own pace.

01 · The rule

The rule

MVC, MVP and MVVM

DabbaGo's kitchen dashboard started as one big file: it fetched orders, applied the "cannot mark ready before cooking starts" rule, and drew the buttons, all mixed together. When the company wanted a tablet version, nothing could be reused, and the rule could not be tested without clicking through the screen. Three classic patterns exist to prevent exactly this.

The rule

Keep the rules out of the screen; patterns differ in who handles input and updates the view.

All three patterns split a user interface into the same first two parts:

  • Model: the data and business rules. Orders, statuses, the rule about when an order may be marked ready. It knows nothing about screens.
  • View: what the user sees. Lists, buttons, colours.

They differ in the third part, the one in the middle.

MVC: Model, View, Controller. The controller receives user input, such as a click or a web request, and tells the model what to do. The view then displays the model's current state. In many web frameworks, a controller handles a request, updates the model, and picks a view to render the response.

MVP: Model, View, Presenter. The view is kept passive: it forwards user actions to the presenter and shows whatever it is told. The presenter talks to the model and then updates the view through a small interface, for example calling showOrders(list). Because the presenter only knows that interface, it can be tested with a fake view.

MVVM: Model, View, ViewModel. The view model exposes state (the order list) and commands (mark ready) that the view binds to. When the view model's state changes, the binding redraws the view automatically; nobody calls "update the screen" by hand. Frameworks with data binding make this natural.

MVC   input → Controller → Model;  View reads Model
MVP   input → View → Presenter → Model;  Presenter updates View
MVVM  View binds to ViewModel;  ViewModel talks to Model
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.