A breakdown of MVC

Christian Cain
2 min readFeb 27, 2020

All great artists have a method to their madness.

No matter how challenging or complex a painting/sculpture might seem to an observer, there is intent in the way everything pieces together to create the overall tone that the artist envisioned.

As programmers we like to think of our programs as works of art in our own right. MVC is a system to abide by that helps to organize our own madness so that everything works cohesively for the sake of our users.

MVC is a reusable design framework that strongly emphasizes the ideas that structure is important, and that you should “separate your concerns”, meaning each aspect of your program should be concerned with a unique task.

MVC makes it easier for an entire team to have multiple heads on a single project. It can allow you to tweak a specific webpage without worrying about breaking your whole app. And if you’re OCD like me, it can help to keep your files organized so that you have confidence in finding them later.

History

We mostly accredit the invention of MVC to a Norwegian computer scientist by the name of Trygve Reenskaug.

While working on SmallTalk-79 at Xerox, Trygve wanted a way to disassociate the data handling logic from the GUI that they were developing.

His work ultimately became what we know of as MVC, and has influenced programming languages such as NEXT, Java, Ruby to state a few.

What does it stand for?

MVC is an acronym for Model-View-Controller.

Model — the data and business logic associated with an application.

View — what the user sees. In the case of a web application, this would be the HTML/CSS that is rendered in the user’s browser.

Controller — the glue that holds everything together! The controller manages requests from the user, delegates tasks to the Model and View, and builds the response.

The request cycle

MVC allows for developers to break down the requests from a user, and build a response in a methodical manner.

When a user sends a request to a server, the server (through a language dependent process) maps the request to a given Controller. The Controller takes in data sent from the user. It then calls on the Model to retrieve additional data from the database, and executes any necessary logic. Once the Controller has the data that it needs, it then calls to the View to render a response that encapsulates the data in a user friendly page. Once the Controller has the page to display, it then serves it as a response to the user.

In conclusion

MVC provides organization for a complex process.

It is a tried and true design principle that all developers should familiarize themselves with. One that I have personally grown to enjoy!

Thanks for reading!

--

--