Skip to content

The Model-View-ViewModel (MVVM) pattern

Pattern · Chapter 7

  • Shares the separation of concerns goal with MVC and MVP, making apps easier to maintain, extend, and test.
  • Distinctive feature: heavy view↔ViewModel interaction via data binding.
  • Works well for rich desktop apps (also web and mobile). Example framework: Windows Presentation Foundation (WPF).
ComponentResponsibility
ModelBusiness domain object and data; uses the database. May bind directly to view/ViewModel properties, so it commonly raises property-changed notifications.
ViewThe UI; the part users see. Active — unlike passive MVC/MVP views, it is aware of the model and ViewModel. Handles its own events but holds no state; relays user actions to the ViewModel (via data binding or commands). Goal: minimize code in the view.
ViewModelAnalogous to the controller/presenter — coordinates view and model. Provides data to views for display/manipulation, handles user actions and input, and holds navigation logic to move between views. Communicates with views via data binding, commands, method calls, properties, and events.
  • The view is active and knows the model (unlike MVC/MVP passive views).
  • The tight view↔ViewModel connection is realized through data binding.
  • Software Architect’s Handbook (Packt, 2018), Ch.7 “The Model-View-ViewModel pattern”, pp. 547-550.