Manu Maheshwari
5 min readApr 17, 2018

THE MVC ARCHITECTURE

MVC, the abbreviation for Model-View-Controller, designed way back in 1979, is an immensely popular programming pattern used to design user interfaces. It has a significant presence in the construction of web applications.

Though it is many-a-times referred to as a framework, but, remember that MVC in itself is not a framework, instead it is a predefined structure of programming that is highly popular among the most used frameworks. Keep in mind, while working with the technical stuff, it is always good to not confuse the identities of terminologies, else it ruins the essence of what is what.

Working of a Website:

Before understanding the details about the MVC, it would be beneficial to look at a structure that is general and then try to figure out how MVC comes into existence. So, the structure we have below is simple. It has three discrete components Client, Server and the Database, moreover, we are none of these three.

For surfing through a website or retrieve matching results regarding our queries, we use a software called Web Browser, for example, Chrome, Firefox, Opera etc. Now here, this web browser is called a Client.

As soon as we type a query in the search engine, the browser does not show the result directly on its own simply because it has nothing to show. Though it receives the result pages in a fraction of seconds, so it may seem like an instantaneous process but there is a lot happening behind the screen which we cannot see. So, after typing the query, the client, that is our web browser sends that query request to the server, that may be big or small as per the size of the website. Not all websites are just hyperlinked web pages, there are database-driven websites that have a large chunk of big data to handle. Servers also have their own language of communication that are called the server-end or server-side languages, some of them are PHP, Ruby & Python.

Till now we have typed a query in our web browser (client) which passes the request to the server, here the request is further processed and forwarded to the Database. Database also has own set of languages, MySQL, PostgreSQL, MongoDB are to name a few. Now, after the query comes to the Database, it processes the request, it finds information related to the search term and sends back to the server. The server processes the received information, presents it in the form web pages and sends back to the client, which is visible to the user on the front end (on the screen)

MVC in Web Development:

The above structure we discussed is simple. Client passes query to the server, which then, after processing forwards it to Database, after receiving the request the database searches the information related to the query and responds to server. From here, server responds to client and user sees the search result pages on the screen.

This structure is generic and we can observe it is repetitive. Every time the same passing and receiving of information or commands will take place. This is the way a website works. So, this repetitive structure, when separated becomes three elements. MVC is analogous to this general structure, M (Model) is the Database, V (View) is our client and C (controller) is a code script on our server that helps in managing this relationship between the Model and the View.

MVC Architecture in Details:

1) Model: The Model element of MVC structure is responsible for data associated tasks like adding and retrieving data from Database or processing data to and from database. It only interacts with the controller (C of the MVC and not us), and does not speak to the View.

2) View: This piece of MVC architecture is simply everything that appears on the screen i.e. the front-end appearance that the user sees. It does not take any decision on its own, only executes the instructions received from the server. It does not interact directly with the Model and can only speak to Controller for query and listen to it for the results.

3) Controller: It is the connecting link between the Model and the view and can interact with either of them. Processes information from client before passing to the Model and vice versa.u

MVC is a predefined architecture of how a web application will be programmed, so, everything has a place for it. If we write a code related to database it will go to the Model, similarly codes linked to processor will go to the controller and that related to frontend appearance in View.

Advantages and Disadvantages of MVC :

Advantages:

1) Modifying the code is much easier at any stage of development as the tasks are well-separated due to the modular form.

2) Similar logics are grouped together and those different are in discrete part of code, these two properties are termed high cohesion and low coupling respectively.

3) Multiple developers can code simultaneously without conflict of overwriting or disturbing each other’s code.

Disadvantages:

1) The programmers need to be well versed with several skills i.e. markup language coding as well as the server-end scripts.

2) Moving in and around the code becomes a bit typical and it becomes tough to understand the layers of code.

Popular web frameworks that follow MVC are:

1) CakePHP (2005): Open source, based on PHP, aims to make quicker yet highly efficient web applications with lesser code

2) Codeigniter (2006): Open source, PHP based, most suitable for small applications and dynamic websites.

3) Ruby on Rails (2005): Often called just Rails, server end framework, coded in Ruby, provides easier ways to use web standards namely XML, JSON, HTML, CSS, JavaScript.

4) Django (2003): Free, Open Source, coded in Python, primarily meant for simplifying the structure of typical websites that rely on large databases.

5) Laravel (2011): Free, Open Source, coded in PHP, provides reliable package installer in modules, also gives multiple ways of traversing relational database, assists application distribution and helps in syntax orientation.

6) ASP.NET (2002): Open Source, Server-end framework, somewhat based on HTML, brought to existence by Microsoft for dynamic web programming.

Apart from these networks iOS is also profoundly developed around MVC.