DEV Community

Sam Saryon
Sam Saryon

Posted on • Updated on

Quick MVC Crash Course!

Introduction

MVC is an acronym that gets used a lot around the developer community especially with those who are full stack developers. By the end of this post you will be able to understand at a high level what an MVC is and why its so popular among developers.

So what exactly is an MVC?

Simply put, MVC is an acronym that stands for Model, View, Controller. It's a software architectural design pattern for organizing your code into three different sections or parts that work interdependently.

Lets dive a little deeper now...

MVC Diagram

Model: The model purpose is to manage all the data for the application. It handles all business logic and notifies the view whenever something in the database was changed so it can render it for the client to see. The model works with Databases such as MongoDB or Postgresql.

View: The view purpose is to contain all the user interface logic for the application. It takes the data from the model and display it on the screen for users to see and interact with. The view usually contains code usually written in a frontend framework such as React, Vue, or Angular.

Controller: The purpose of the controller is to be the bridge between the view and the model. When a user interaction is dispatched in the view the controller is listening for that request so it can talk with the model and update the logic and send it back to the view. The controller is the server and can be written in languages such as Node, Python, etc.

So now that you understand what the MVC model is lets take a look at why its so popular...

Why is the MVC model so popular?

One of the main reasons that the MVC pattern is so popular is because of its flexibility and organization. As I explained before, every component or piece of the MVC model is separated and work interpedently. The reason this matters is because this allows you to modify each part without effecting another. For example, if you decide to change the view in your application from Angular to React, you'll have a lot easier of a time doing so since the View piece is abstracted. Similarly, if you wanted to switch your database from MongoDB to MySQL, you can do this in the model without having to make huge changes across other pieces of your code. Another huge reason is because of the modularity the MVC pattern offers you can have more than one developer work on an application together. You could have someone working on the view while another developer could be working out the logic for the model.

Top comments (0)