MVC Architecture, Simply Explained!

Niroshan Ratnayake
4 min readApr 19, 2021

--

Introduction to MVC architecture

In the early days, there was no specific structure to create applications. Since the complexity of applications started increasing daily, people used to find new ways of creating applications that can help to create applications fast and easy. One such architectural paradigm for programming is MVC, which was designed in 1979.

MVC stands for Model-View-Controller. It is a software design pattern with an architecture that helps to create huge applications easy. But it doesn’t belong to a specific programming language or framework. It’s just an architecture that can be used to create any kind of application in many languages and frameworks. To use frameworks efficiently and easily, understanding MVC is really helpful. Rails, CakePHP, Django, Laravel, AngularJS are some of the frameworks that use MVC architecture.

some of the frameworks that use MVC architecture

Design Diagram

High-level architecture of MVC

Model, View and Controller are three different parts of MVC architecture. Each part plays an important role in application development.

Why and where architecture is used?

In an application, software components are to be done one thing. If the components start doing more than one thing, things will become more complicated and the code readability will decrease. Basically, the Models contain the business logic where it represents the things in your application. The view presents the data to the user. The controller decides what to do with the various user actions. When you stick to that, the code is easy to read because things are as simple as possible. The idea behind MVC will be more helpful when the project gets much more complex. For a simple application like to-do, it may not be that much helpful. But for huge projects and Enterprise applications, MVC architecture gives more and more value. Simply put MVC architecture is a way of thinking or way of structuring web applications in such a way that you never repeat yourself which result in a very well organised, structured and clean codebase.

The Model — (Interacting with database)

This is more into Adding and retrieving items from the DB, Processing data from or to the DB. Most of the time the model speaks only with the controller.

The View — (Displaying to the User)

This is the only thing the user ever sees. Most of the time speaks only with the controller. (view usually doesn’t interact with the model, but for some situation, it can be done). This can bethink as a webpage in a browser and that's all you see. No logic or database you will see. The view is there for the user to interact and the rest are done by The Controller and The Model

The Controller — (Interacting with the user actions and responses from the model)

Processes GET/POST/PUT/DELETE request. Act as a middle man to take information/data from the user, process information/data and talk to the DB if needed, Receive information from DB. Speaks to the view in order to explain the presentation to the viewer. And controller indirectly connects with the user because what the user wants to do is obviously the controls in the controller.

Advantages and Disadvantages

pros and cons in MVC architecture

Every architecture has its advantages and disadvantages. It is the same with the MVC architecture.

Advantages of MVC architecture :

  1. The development of the applications is super fast.
  2. Easy for multiple developers to collaborate and work together.
  3. Update the application is really easy.
  4. Debugging made easier as we have multiple levels properly written in the application.
  5. Offers the best support for test-driven development
  6. Provides clean separation of concerns (SoC).
  7. Search Engine Optimization (SEO) Friendly.
  8. Suits more for apps that are done with large teams of web designers and developers.

Disadvantages of MVC architecture :

  1. MVC architecture is bit hard to understand
  2. Must have strict rules on methods.
  3. Knowledge of multiple technologies is required
  4. Lots of code maintain in the controller

When we come across the advantages, the disadvantages can be neglected since the disadvantages are not so huge when comparing to the advantages. In conclusion, MVC architecture provides lots of advantages where programmers are being benefited.

--

--

Niroshan Ratnayake
Niroshan Ratnayake

Written by Niroshan Ratnayake

Tech Writer | Software Developer | Undergraduate — University of Moratuwa, Faculty of Information Technology. https://niroshan.netlify.app/

No responses yet