What’s the difference between a ViewModel and Controller?

The ViewModel is a Pattern used to handle the presentation logic and state of the View and the controller is one of the fundamentals parts of any MVC framework, it responds to any http request and orchestrates all the subsequent actions until the http response.

The ViewModel Pattern: More info

In the ViewModel pattern, the UI and
any UI logic are encapsulated in a
View. The View observes a ViewModel
which encapsulates presentation logic
and state. The ViewModel in turn
interacts with the Model and acts as
an intermediary between it and the
View.

View <-> ViewModel <-> Model

The Controllers (Comes from the Front Controller Pattern): More Info

It “provides a centralized entry point
for handling requests.”

HTTP Request -> Controller -> (Model,View)

–Plain Differences:–

  • While the ViewModel is an optional
    pattern the Controller is a must, if
    you are going the MVC way.
  • The ViewModel encapsulates
    presentation logic and state, The
    Controller orchestrates all the
    Application Flow.

Leave a Comment