Module 4 (Chapter 2) PDF
Module 4 (Chapter 2) PDF
MODEL-VIEW-CONTROLLER
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.
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.
MVC Structure
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