What is MVC vs. MVVM Pattern

How do you compare the Model-View-Controller (MVC) design pattern with the Model-View-ViewModel (MVVM) design pattern? What is the difference between the MVC and MVVM design patterns? I’ll try to explain here.

The most obvious answer, and the most over-simplified answer is that MVC is primarily a server-side programming pattern, while MVVM is more often a client-side pattern.

MVVM is concerned with keeping the View up-to-date with the server data in the Model and ViewModel. The ViewModel is a special object separate from the Model (though not always). In a web app using MVVM the Model usually represents the data on a server, while the ViewModel is the data on the client. MVVM often also uses the Observer pattern to keep the View in sync with the ViewModel data that backs it up, and the same for the ViewModel and Model. When a change in the Model or ViewModel data is observed the View will refresh itself to show the latest Model data. Likewise, when a form is used in the View to update the Model these changes can be passed back to the Model on the server immediately.

MVC is an application structure that is a little more complicated than that. MVC uses a Controller to populate a Model and give it to the View for the View to display. MVC usually also has a few other components in it like a Router to activate different Controllers and Binders to create Models and populate the values from a client (like a web browser).

The obvious difference is the C in MVC: the Controller object which changes and manages the Model and View. In MVC the Controller is arguably the smartest component of the three, while in MVVM the components are more interlocked because changes to one automatically affect the other. The Controller is responsible for creating the Model and choosing the View. The View will consume the Model data to display. Likewise when returning data (say a POST from a web browser form) the Router will pick the Controller to activate and create a Model based on the data coming back from the View and give it to the Controller to use. The Controller will then do some work.

Sometimes MVVM and MVC design patterns are used together, MVVM on the client and MVC on the server.

MVC sounds more complicated, but actually in the end we have so many helper frameworks that implementing MVC or MVVM becomes almost trivial. I don’t think either Design Pattern is better than the other, so you should learn them both and choose to use the best fit for your technology stack and situation.

Leave a Reply

Your email address will not be published. Required fields are marked *