Skip to content

What is MVC Architecture? And Why Should You Care?

1200px MVC Process

MVC is known as an architecture pattern. It divides the application into three logical parts: the model part, the view, and the controller. It was used for desktop graphical user interfaces but is now used for designing mobile applications and web applications.

History of MVC Architecture

model view controller
Model View Controller

MVC architecture invented by Trygve Reenskaug The first reports on MVC were written when I visited a scientist at the Xerox Palo Alto Research Laboratory (PARC) in 1978/79. Initially MVC was called “Thing Model View Editor” but quickly changed it to “Model View Controller“.

Features of MVC Architecture

  • Easy and smooth testability. Highly testable, extensible and pluggable structure.
  • To design a web application architecture using the MVC pattern, it offers full control over its HTML code and URLs.
  • Leverage existing features provided by ASP.NET, JSP, Django, etc.
  • Model, View, Controller. Separation of application tasks viz. business logic, Ul logic, and input logic
  • URL routing for SEO friendly URLs. Powerful URL mapping for understandable and searchable URLs
  • Supports for Test Driven Development (TDD)

Model

  • A model is an object that represents data or even activities, such as a database table or even a production machine process on the shop floor.
  • The model manages the behavior and data of the application domain, responding to requests for information about its state and responding to state change instructions.
  • The model represents the organization’s data and the business rules that govern access to and updates to that data. The model often serves as a software approximation of a real-world process, so simple real-world modeling techniques are used when defining the model.
  • The model is the piece that represents the low-level state and behavior of the component. Manages the state and performs all transformations for that state.
  • The model has no specific knowledge of its controllers or its views. The view is the piece that manages the visualization of the state represented by the model. A model can have more than one view.

Note that the model may not necessarily have a persistent data store (database), but if it does it may access it through a separate Data Access Object (DAO).

View

  • A view is a few shape of visualization of the state of the model.
  • The view manages the graphical and/or textual output to the part of the bitmapped show this is allotted to its application. Instead of a bitmapped show the view can also additionally generate HTML or PDF output.
  • The view renders the contents of a model. It accesses organization information via the version and specifies how that information need to be presented.
  • The view is answerable for mapping images onto a device. A view usually has a one to 1 correspondence with a display surface and is aware of a way to render to it. A view attaches to a model and renders its contents to the display surface.

Controller

  • A controller provides facilities to change the state of the model. The controller interprets the user’s mouse and keyboard input and directs the model and/or view to change accordingly.
  • A controller is the means by which the user interacts with the application. A controller accepts user input and directs the model and view to perform actions based on that input. In fact, the controller is responsible for assigning the end user’s action to the application response.
  • The controller translates interactions with the view into actions performed by the model. In a standalone GUI client, user interactions can be button clicks or menu selections, while in a web application they appear as HTTP GET and POST requests. Actions performed by the model include activating business processes or changing the state of the model. Based on user interactions and the result of model actions, the controller reacts by choosing an appropriate view.
  • The controller is the piece that manages user interaction with the model. It provides the mechanism by which changes are made to the state of the model.

Related Articles

What Is Join And Types Of Join In Mysql

CodeIgniter Interview Questions And Answers

Function Overloading And Overriding In PHP

Difference Between GET And POST Method In PHP

Tags: