In: Computer Science
C) Explain MVC architectural pattern and its components. Draw a diagram that describes the pattern. Describe the behavior of MVC by using online shopping application that has the following responsibilities: browse catalog, add item to shopping cart, remove item from shopping cart, display shopping cart. State the two advantages and two disadvantages of using this pattern.
Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications.
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.
The Model
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
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 and very easy to integrate with AJAX technology.
The Controller
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.
The following figure illustrates the interaction between Model, View and Controller.
Suppose in out application we have design five web pages i.e. welcome page (home page entry point to our application where our main categories of products will be shown), Category page (which will show us the list of different products also it will show us shopping cart option and proceed to checkout option), cart page (which will show us the list of all the product items which we have selected for purchasing),checkout page (which will be used to collect the user personal information as well as it will provide the order summary) and confirmation page (which will show the information that his order has been successfully placed) (Figure).
Before we start the development of application we should decide that which type of architecture we should use to develop our application. We should examine the functional components of our application and determine the way through which they will communicate with each other.There are many design patterns are available which can be used to develop an application. Here we are going to use MVC architecture pattern.
MVC pattern divides our application into three major components i.e. Model, View and Controller. Model is used to communicate with our database. View is used to get data from model and present it to the user. And finally, the controller is used to define the application behavior. It interacts with the inputs of the users. Normally in web-based application user’s inputs are HTTP GET and HTTP POST. Detail about the
Advantages
1. Faster Web Application Development Process:
MVC offers support for rapid and parallel development. So, developing web applications using the MVC model it is possible that one developer work on the view while the another can work on the controller. This helps for easy implementation of the business logic of the web application. It surely benefits developers for completing the web application three times quicker compares with the applications that are developed using other development patterns.
2. MVC Web Application Supports Asynchronous Technique:
.Net developers can integrate MVC architecture with JavaScript Framework. It means that MVC applications can be made to work even with PDF files, site that runs only on the specific browsers, and also for the desktop widgets. MVC also allows using the asynchronous technique, which allows web developers to build faster loading web apps.
disadvantages
1)Increased complexity
2) Inefficiency of data access in view
3) Difficulty of using MVC with modern user interface.
4) Need multiple programmers
If you have any query regarding the answer please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.