0% found this document useful (0 votes)
99 views

Module 4 (Chapter 2) PDF

The document discusses the Model-View-Controller (MVC) architectural pattern. MVC divides an application into three interconnected parts: the model, the view, and the controller. The model manages the application's data and logic, the view displays the model's data to the user, and the controller handles user input and interacts with the model and view. MVC separates an application's internal representations from user interface interactions and improves code reuse and parallel development. Popular web frameworks use MVC to structure applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Module 4 (Chapter 2) PDF

The document discusses the Model-View-Controller (MVC) architectural pattern. MVC divides an application into three interconnected parts: the model, the view, and the controller. The model manages the application's data and logic, the view displays the model's data to the user, and the controller handles user input and interacts with the model and view. MVC separates an application's internal representations from user interface interactions and improves code reuse and parallel development. Popular web frameworks use MVC to structure applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of CSE GITAM UNIVERSITY

MODEL-VIEW-CONTROLLER

 Model–view–controller (MVC) is an architectural pattern commonly used for developing


web applications.
 It is also used for developing user interfaces that divides an application into three
interconnected parts.
 This is done to separate internal representations of information from the ways information is
presented to and accepted from the user.
 The MVC design pattern decouples these major components allowing for efficient code
reuse and parallel development.
 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 straight.
 A Model View Controller pattern is made up of the following three parts −
 Model − The lowest level of the pattern which is responsible for maintaining data.
 View − This is responsible for displaying all or a portion of the data to the user.
 Controller − Software Code that controls the interactions between the Model and View.
 MVC is popular as it isolates the application logic from the user interface layer and supports
separation of concerns.
 Here the Controller receives all requests for the application and then works with the Model to
prepare any data needed by the View.
 The View then uses the data prepared by the Controller to generate a final presentable
response.
 The MVC abstraction can be graphically represented as follows.

Diagram of interactions within the MVC pattern.

Spandan G, Assistant Professor Page 1


Department of CSE GITAM UNIVERSITY

MVC –COMPONENTS
A Model View Controller pattern is made up of three components −

 The Model
 The model is the central component of the pattern. It expresses the application's
behavior in terms of the problem domain, independent of the user interface. It directly
manages the data, logic and rules of the application.
 The model is responsible for managing the data of the application. It responds to the
request from the view and it also responds to instructions from the controller to update
itself.
 The View
 A view can be any output representation of information, such as a chart or a diagram.
Multiple views of the same information are possible, such as a bar chart for
management and a tabular view for accountants.
 It means presentation of data in a particular format, triggered by a controller's decision
to present the data. They are script-based templating systems like JSP, ASP, PHP.
 The Controller
 The third part or section, the controller, accepts input and converts it to commands for
the model or view.
 The controller is responsible for responding to the user input and perform interactions
on the data model objects. The controller receives the input, it validates the input and
then performs the business operation that modifies the state of the data model.

Interactions
In addition to dividing the application into three kinds of components, the model–view–
controller design defines the interactions between them.

Spandan G, Assistant Professor Page 2


Department of CSE GITAM UNIVERSITY

 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 is responsible for responding to the user input and perform interactions on
the data model objects. The controller receives the input, optionally validates the input and
then passes the input to the model.

MVC Architecture
 The MVC architectural pattern has existed for a long time in software engineering. All
most all the languages use MVC with slight variation, but conceptually it remains the same.
 MVC stands for Model, View and Controller. MVC separates application into three
components - Model, View and Controller.
 Model: Model represents shape of the data and business logic. It maintains the data of the
application. Model objects retrieve and store model state in a database.
 Model is a data and business logic.
 View: View is a user interface. View display data using model to the user and also enables
them to modify the data.
 View is a User Interface.
 Controller: Controller handles the user request. Typically, user interact with View, which
in-tern raises appropriate URL request, this request will be handled by a controller. The
controller renders the appropriate view with the model data as a response.
 Controller is a request handler.
 The following figure illustrates the interaction between Model, View and Controller.

MVC Architecture

 The following figure illustrates the flow of the user's request in MVC.

Spandan G, Assistant Professor Page 3


Department of CSE GITAM UNIVERSITY

Request/Response in MVC Architecture


 In 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 Structure

 The model-view-controller or MVC is software architecture commonly used for creating


web applications or software.

Spandan G, Assistant Professor Page 4


Department of CSE GITAM UNIVERSITY

 In other words, it’s a structure for web applications to follow in order to ensure efficiency
and consistency.
 Many of the most popular frameworks use the MVC architecture.

(Note: write explanation in your own sentence to the above diagram by using the
concepts of model, view and controller)

ADVANTAGES
 Enables the full control over the rendered HTML.
Provides clean separation of concerns (SoC).
 It enables you to create test Driven Development (TDD). Easy integration with client
side script (example: JavaScript) frameworks.
 A separation of concern is a main advantage of MVC. It means we can divide into three
part of the application.
 In the same time we can split many developers' work at one time. It will not affect one
developer's work to another developer's work.
 Latest version of MVC supports default responsive web site and mobile templates.

DISADVANTAGES
 Cannot see design page preview, Every time we want to run it, then we see the design.
 Understanding flow of application is very hard.
 It is a little bit complex to implement and not suitable for small level applications.
 Its deployment is a little bit hard

Spandan G, Assistant Professor Page 5

You might also like