What Is MVC Framework?

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

What is MVC Framework?

The Model-View-Controller (MVC) framework is an architectural pattern that


separates an application into three main logical components Model, View, and
Controller. Hence the abbreviation MVC. Each architecture component is built
to handle specific development aspect of an application. MVC separates the
business logic and presentation layer from each other. It was traditionally
used for desktop graphical user interfaces (GUIs). Nowadays, MVC
architecture in web technology has become popular for designing web
applications as well as mobile apps.
In this MVC tutorial, you will learn more about MVC basics-

 History of MVC
 Features of MVC
 MVC Architecture
 MVC Examples
 Popular MVC web frameworks
 Advantages of MVC: Key Benefits
 Disadvantages of using MVC
 3-tier Architecture vs. MVC Architecture

History of MVC
 MVC architecture was first discussed in 1979 by Trygve Reenskaug
 MVC model was first introduced in 1987 in the Smalltalk programming
language.
 MVC was first time accepted as a general concept, in a 1988 article
 In the recent time, MVC pattern is widely used in modern web
applications

Features of MVC
 Easy and frictionless testability. Highly testable, extensible and
pluggable framework
 To design a web application architecture using the MVC pattern, it offers
full control over your HTML as well as your URLs
 Leverage existing features provided by ASP.NET, JSP, Django, etc.
 Clear separation of logic: 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
comprehensible and searchable URLs
 Supports for Test Driven Development (TDD)

MVC Architecture
Here is the detailed architecture of MVC framework:

MVC Architecture Diagram


Three important MVC components are:

 Model: It includes all the data and its related logic


 View: Present data to the user or handles user interaction
 Controller: An interface between Model and View components

Let’s see each other this component in detail:

View
A View is that part of the application that represents the presentation of data.

Views are created by the data collected from the model data. A view requests
the model to give information so that it presents the output presentation to the
user.

The view also represents the data from charts, diagrams, and tables. For
example, any customer view will include all the UI components like text boxes,
drop downs, etc.

Controller
The Controller is that part of the application that handles the user interaction.
The controller interprets the mouse and keyboard inputs from the user,
informing model and the view to change as appropriate.

A Controller send’s commands to the model to update its state(E.g., Saving a


specific document). The controller also sends commands to its associated
view to change the view’s presentation (For example scrolling a particular
document).

Model
The model component stores data and its related logic. It represents data that
is being transferred between controller components or any other related
business logic. For example, a Controller object will retrieve the customer info
from the database. It manipulates data and sends back to the database or
uses it to render the same data.

It responds to the request from the views and also responds to instructions
from the controller to update itself. It is also the lowest level of the pattern
which is responsible for maintaining data.
MVC Examples
Let’s see Model View Controller example from daily life:

Example 1:

 Let’s assume you go to a restaurant. You will not go to the kitchen and
prepare food which you can surely do at your home. Instead, you go
there and wait for the waiter to come on.
 Now the waiter comes to you, and you order the food. The waiter
doesn’t know who you are and what you want he just written down the
detail of your food order.
 Then, the waiter moves to the kitchen. In the kitchen, waiter does not
prepare your food.
 The cook prepares your food. The waiter is given your order to him
along with your table number.
 Cook then prepared food for you. He uses ingredients to cooks the food.
Let’s assume that your order a vegetable sandwich. Then he needs
bread, tomato, potato, capsicum, onion, bit, cheese, etc. which he
sources from the refrigerator
 Cook final hand over the food to the waiter. Now it is the job of the
waiter to moves this food outside the kitchen.
 Now waiter knows which food you have ordered and how they are
served.

In this MVC architecture example,


View= You
Waiter= Controller
Cook= Model
Refrigerator= Data
Let see one more MVC model example,

Example 2:

Car driving mechanism is another example of the MVC model.

 Every car consist of three main parts.


 View= User interface : (Gear lever, panels, steering wheel, brake, etc.)
 Controller- Mechanism (Engine)
 Model- Storage (Petrol or Diesel tank)

Car runs from engine take fuel from storage, but it runs only using mentioned
user interface devices.

You might also like