In modern web programming, the MVC (Model-View-Controller) architecture is widely used. Many of the most popular frameworks employ MVC; however, it is not an application, it is a design pattern – a prescribed solution to a common problem organized in code.

Similarly, It is also known as an architectural pattern. MVC can be considered as layer-based architecture. That is, the controller, model, and view are the three layers all of which are related to one another.

Controllers hold the main control of the program. A controller is responsible for the program flow. It is also the first layer in web-based MVC applications, which is called when the browser hits the URL.

Models hold the main data of the program such as information from database objects and SQL queries. All data can be gained from the models; however, the models cannot be directly called – it is a controller who requests a model for specific data and the model performs the request and returns the data to that controller.

A view is the last layer of the MVC Architecture which holds the user interface of the program. In web applications, a view contains HTML, CSS, JavaScript, XML or JSON, etc. The view is a visible layer to the user whereas the models and controllers are hidden from the user.

Let’s understand about MVC with the help of conversation form when a user hits the URL:

  • Controller: Hey ABC Model: The user wants the XYZ Data, please pass it to me.
  • Model: Got the XYZ Data! Here it is.
  • Controller: Hey ABC View, I am passing the XYZ Data to you.
  • View: Renders the information on the page for the user to see.

Tagged in:

, ,