What Is MVC?

What Is MVC?

ยท

3 min read

Software development can be a messy affair when it is developed in an unstructured way, this is why a lot of architectural patterns have been developed to help developers collaborate on a project or extend the utility of the project regardless of if they were on the founding team. One of the most popular architectural patterns is the MVC which stands for Model, View, and Controller. This architecture gives a project so much structure that any developer can pick up the software solution and know where to find what they're looking for.

relatable explanation.jfif

A RELATABLE EXPLANATION

Software development involves creating tens (if not hundreds) of different files that house code, it can be a bit of a chore to locate a particular file in order to effect a particular change, this is why categorizing code files based on the kind of code they house is useful. The Model folder holds code files (and classes) that interact directly with the database, the classes in the model class hold properties which features in the database as columns in the database table, while the class represents the table itself.

drone-3453361_1280.jpg

WHERE THE VIEW AND CONTROLLER COME IN

The View folder contains frontend files that interact directly with the end-users (you and I ๐Ÿ˜‰), everything you see in an MVC application is made available to you via the code files found in the Views folder. frontends developers will stick to that folder. The Controller folder houses code that can be termed the middle-man in the sense that it interacts with both the model classes (code files in the model folder) and the Views classes (code in the Views folder). It is where things like APIs are declared.

The Controller in a way determines which view is rendered to the end-user and manipulates data that is passed between the model and the view. It takes data from the view and passes it to the model (albeit with some manipulation) and does the exact same thing when the user wants some data from the database (which the model class provides).

finally.jfif

FINALLY

MVC is arguably one of the easiest architectural patterns to learn because of its simplicity which is why a lot of junior developers tend to be able to come to terms with it, the idea that a software solution is broadly divided into three is one that offers search convenience. MVC isn't without its potential drawbacks, one of which is the ease at which end-users can send data directly to the database because there is no filter in place to expose only what is needed to the end-users. To mitigate this, we use DTO (Data Transfer Objects) among others.

I just remembered that yesterday, I promised to write on authorization, authentication and broken access control ๐Ÿ˜…, I guess I'll be quite busy this week in covering up all of these with DTO now on the queue. You'll just have to wait and see which I write about tomorrow ๐Ÿ˜.