DEV Community

Cover image for MVC - What is it?
Ronnie
Ronnie

Posted on • Updated on

MVC - What is it?

Model. View. Controller.
What are those?

Model: They represent the data. That's it! They don't depend on controllers, but they can communicate with them.

View: They display the models data, by way of the controller and send user actions back to the controller.

Controller: They send model data to the view and interpret user actions.

What's the big deal?
MVC helps keep our concerns separated. We have three moving parts: data, display of data and communication between the two. Keeping these jobs separate makes creating simple and less buggy code a lot easier. If we had all that code in one file, we'd be pulling all of our hair out pretty quickly.

Real Life Example:
Let's think about it like we're going out to eat. You (a user) sit down at your table and take a look at a menu (sounds like a view to me). After a few minutes, you decide what you'd like to eat (a user request). Your server (controller) takes that order back to the kitchen (the model). After your server brings your order to the kitchen, the cooks start preparing it. If all goes according to plan, your server should be bringing the food you ordered back to your table in a reasonable amount of time. There is now a nice looking plate of food sitting in front of you, which may be the best kind of updated view there is!

Top comments (0)