How MVC Works

How MVC Works

MVC is a design pattern that stands for Model-View-Controller. What is strives to do is separate the concerns of an application’s presentation layer by assigning specific roles to the three different components.

The Controller is responsible for handling all user input. Once input has been received, the Controller will perform any operations/actions it needs to, which might include interacting with the Model.

The Model represents the data in the application. Once the Controller retrieves some model data and performs any work with the model, it constructs a presentation model that describes the model in terms the View can understand.

The View is the visual representation of the model. It presents the model data to the actual user in a way that is meaningful. In a web application, this would typically be HTML.

What does MVC look like?

So what does MVC look like when implemented over the web?

When an HTTP request comes into the application it is mapped to a controller. Remember as we mentioned in the previous slide, in the MVC design pattern, the controller is the piece of the triad that handles all user input. In the case of a web application, user input is represented as HTTP requests.

Once the controller has received input, it performs whatever operations it needs to and then assembles a presentation model.

The controller then takes the model and passes it off to the view. Remember that the view is simply a visual representation of the model.

The view then “transforms” the model into whatever format it uses to represent it. In a web application, this would typically be HTML.

The view then serves the request by responding with its visual representation.

How MVC Works How MVC Works Reviewed by Bhaumik Patel on 7:23 PM Rating: 5