You are on page 1of 16

Model View

Controller (MVC)

CSE-313
System Analysis & Design

Mohammad Shariful Islam


Lecturer, Department of CSE
Mobile: +8801747612143
Email: sharifulruhan@gmail.com
Background
MVC is a popular way of organizing your
code. The big idea behind MVC is that
each section of your code has a purpose,
and those purposes are different. Some of
your code holds the data of your app,
some of your code makes your app look
nice, and some of your code controls how
your app functions.
What is MVC?
 MVC is one of the most frequently used industry-
standard web development framework to create
scalable and extensible projects.
 The Model-View-Controller (MVC) is an
architectural pattern that separates an application
into three main logical components:
 the model, the view, and the controller.
 Each of these components are built to handle
specific development aspects of an application.
MVC History
 Presented by Trygve Reenskaug in 1979.
 It has been used for the first time in
Smalltalk-80 framework.
 Used in making Apple interfaces (Lisa and
Macintosh).
 Then adopted and popularized by Java.
MVC
 Traditionally used for desktop graphical user
interfaces (GUIs),
 This architecture has become popular for
designing web applications and even mobile,
desktop and other clients.
 Popular programming languages like Java,
C#, Ruby, PHP and others have popular MVC
frameworks that are currently being used in
web application development.
AN ANALOGY
 MVC is a way to think about how an web
application works.
 It’s kind of like how you make Thanksgiving
dinner. You have a fridge full of food, which
is like the Model. The fridge (Model)
contains the raw materials we will use to
make dinner.

AN ANALOGY
You also probably have a recipe or two. A
recipe (assuming you follow it exactly) is like
the Controller of Thanksgiving dinner. Recipes
dictate which stuff in the fridge you’ll take out,
how you’ll put it together, and how long you
need to cook it.
 Then, you have table-settings, silverware, etc.,
which are what your hungry friends and family
use to eat dinner. Table-top items are like the
View. They let your guests interact with your
Model and Controller’s creation.
MVC Components
MVC separates application into three
components –
 Model,
 View and
 Controller.
MVC Components
 Model: The Model component corresponds to
all the data-related logic used by a program.
For example, this may be a database, file, or a
simple object, such as an icon or a character
in a video game.

Model is a data and business logic.


MVC Components
 View: The View component is used for all
the UI logic of the application. For example,
the Customer view will include all the UI
components such as text boxes, dropdowns,
etc. that the final user interacts with.

View is a User Interface.


MVC Components
 Controller: Controllers act as an interface
between Model and View components . It updates
both models and views. It accepts input and
performs the corresponding update. For example,
a controller can update a model by changing the
attributes of a character in a video game. It may
modify the view by displaying the updated
character in the game.
Controller is a request handler.
MVC
 The following figure illustrates the interaction between Model,
View and Controller.

MVC Architecture
MVC
 The following figure illustrates the flow of the user's request in
ASP.NET MVC.

Request/Response in MVC Architecture


MVC
 As per the above figure, when the user
enters a URL in the browser, it goes to the
server and calls appropriate controller. Then,
the Controller uses the appropriate View and
Model and creates the response and sends it
back to the user.
MVC
Points to Remember :
 MVC stands for Model, View and Controller.
 Model is responsible for maintaining
application data and business logic.
 View is a user interface of the application,
which displays the data.
 Controller handles user's requests and
renders appropriate View with Model data.

You might also like