What is MVC?

If you are here then I’ll assume that you are new to programming or just starting to use a web framework. Welcome aboard soldier ( I’ll assume you like some humors too 🙂 ). You might be hearing everywhere that this framework follows MVC and that framework also follows MVC. You might be wondering what exactly is this MVC everyone is referring to. There’s a high chance that you might as well be very confused. But worry not, we are here to help.

Model-View-Controller(MVC)

MVC flow diagram
MVC flow diagram

The Model-View-Controller, known as MVC in short, is an architectural design pattern that separates an application’s system into three main components. The Model, The View and The Controller. Each of these components are important and handles a specific development aspect of an application. From the figure above, you can summarize that all the inputs from the view (user in this case) goes to the controller where some instructions are applied and the controller interacts with the model. The model then responds with some data, which again is subjected to some instructions and then it is rendered to the view by the controller. This is the basic explanation of how a MVC pattern works.

Do you want to know more? Worry not, that’s next!

Let’s understand about each components in detail, shall we?

The Model

A model is the level in our application which represents the application’s data to the user. It defines where the data objects of our application is stored as it has direct communication with the database itself. It does not concern itself with what’s going on with controller and view unless that has something to do with the model itself. However, if there is any changes made to the model, it will notify the controller about the changes. A model could be a single object or a structure of objects.

The View

A view is where the UI/UX logic of our application is written. This component acts as an interface between our users and our application. A view does not display anything by itself, rather displays the content that it is told to display generally by the controller or sometimes the model as well.

The Controller

The controller handles all the logical operations in the application. It acts as an interface between our view and our model components and processes the business logic of our application. Also, the controller handles all the incoming requests, processes it and renders the output data to the view by interacting with the model data (if needed). In short, controller is the brain of the MVC architecture.

If we put all three of these components in one place, we have our Model-View-Controller (MVC) architecture pattern. Most of the modern frameworks follow this pattern, especially web, because this pattern makes our code and system much more optimized and manageable at the same time. Adding to this, it also makes the implementation of the DRY (Don’t Repeat Yourself) concept very easy, which leads to further enhancement and optimization of our code.

Conclusion

It might be hard to understand what MVC is at first, but in time it will be just an easy yet extremely powerful concept and you will be using it all the time. We hope we were able to help you understand what MVC is. If you have any queries or suggestions for us, feel free to contact us here.

Sharing is caring!

Related Post