DEV Community

Seth A Burleson
Seth A Burleson

Posted on • Edited on

What is MVC?

You've heard it all around the internet talking about programs, MVC is a common topic. Understanding this topic is key to progressing into more advanced web development and moving away from simple single page apps.

What is MVC?

MVC stands for Model View Controller and describes the 3 components of your server-side web app. It is different from a single page app not only because it runs on the server instead of the user's machine, but the code is generally a bit more organized as well.

Model

The model holds that data used by the application. Its usually defined by a class in object oriented languages like C# or Java, but it can be a database like MongoDB or SQLite. Only one model is supplied per page, but it may have other models nested within, depending on what the page needs.

View

The view is rendered on the server and returned to the user. This is generally an HTML template filled with data (data which comes from the model) by the controller.

Controller

The controller handles receiving requests from the user, performing logical operations, combining those with the model of the data, and returning the proper view to the user.

What are the advantages?

The biggest advantage of MVC framework is the ability to separate logic between display logic and business/application logic. This results in cleaner, more organized code that is not only easier to manage and navigate, but also easier to debug and improve. Another advantage is security. Separating your scripts from the visual part of the data can prevent malicious entities from interfering with your code.

How do you think about MVC frameworks? What do you use to organize your code?

Top comments (2)

Collapse
 
shawnatwrussell profile image
sgccoder

I understand MVC more than I did JavaScript.

Collapse
 
sudarshansb143 profile image
sudarshan

I preferred the MVT (Model - View - Template) pattern of Django.