s

what is MVC? edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 07 January 2021 | 1716

Model–view–controller (MVC) is a software design pattern commonly used for developing a user interface that divides the related program logic into three interconnected elements, the Model, View & Controller. It is not a recent pattern it has been in existence since 1970, It is a modularization pattern which means software application is broken into different modules, in this case, it is broken into 3 different components the Model View & the Controller. It is a widely used pattern, It is the central pattern for many frameworks. Traditionally used for the desktop graphical user interface (GUIs), this pattern has become popular for designing web applications. It's popular among programming languages like JavaScript, PHP, Java, C#, Python, etc. The first program that I wrote using the MVC design pattern was in java.

The central idea behind MVC pattern are as follows.

  1. Reusability
  2. Separation of concerns
  3. Maintainability and testability

MVC has three main components Model, View & the Controller.

Model

The model handles data and is the central component of the pattern. It is the application's dynamic data structure, independent of the user interface. It directly manages the data, logic, and rules of the application.

View

View handles presentation

Controller

The controller handles decisions. Accepts input and converts it to commands for the model or view.

In addition to dividing the application into these components, the model–view–controller design defines the interactions between them.

    • The model is responsible for managing the data of the application. It receives user input from the controller.
    • The view means presentation of the model in a particular format.
    • The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.

Although originally developed for desktop computing, MVC has been widely adopted as a design for World Wide Web applications in major programming languages. Several web frameworks have been created that enforce the pattern. These software frameworks vary in their interpretations, mainly in the way that the MVC responsibilities are divided between the client and server. Some web MVC frameworks take a thin client approach that places almost the entire model, view and controller logic on the server. This is reflected in frameworks such as Django, Rails, ASP.NET MVC and the Phoenix (web framework). In this approach, the client sends either hyperlink requests or form submissions to the controller and then receives a complete and updated web page (or other document) from the view; the model exists entirely on the server.

One of the key rules in the MVC pattern is that the connection between the model and the view should always be through the controller. This means if the model has changed and if the view needs to be changed then it has to connect through the controller or if the view has changed and any update from the view to the model should be though the controller.