Presentation is loading. Please wait.

Presentation is loading. Please wait.

MODEL VIEW CONTROLLER PATTERN. Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic.

Similar presentations


Presentation on theme: "MODEL VIEW CONTROLLER PATTERN. Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic."— Presentation transcript:

1 MODEL VIEW CONTROLLER PATTERN

2 Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic. Domain Logic The primary goal of MVC is to isolate UI changes and prevent them from requiring changes to the Domain Logic of the application.Domain Logic MVC divides an application into three concerns: Model - Encapsulates core application data and functionality Domain Logic. Domain Logic View - obtains data from the model and presents it to the user. Controller - receives and translates input to requests on the model or the view.

3 MVC A model: An object that stores data that often pertains to real world responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). A view: Some form of visualization of the state of the model. A controller: Offers facilities using which the user can change the state of the model. clicking on buttons, sliding a slider, typing in a text box, etc.

4 MVC – What Is the problem? The same enterprise data needs to be accessed when presented in different views: e.g. HTML, JFC/swing, XML The same enterprise data needs to be updated through different interactions Supporting multiple types of views and interactions should not impact the components that provide the core functionality of the enterprise application

5 MVC – Solution Separate core business model functionality from the presentation and control logic that uses this functionality Allows multiple views to share the same enterprise data model Makes supporting multiple clients easier to implement, test, and maintain

6 Example MVC a b c a b c Views Controller Model abc 503020 a = 50% b = 30% c = 20% See Interact

7

8 A spinner

9 Architecture Diagram View model representation Model business logic Controller user interaction UpdateEvent User Actions Change View SetState Get State

10 MVC – Responsibilities Model - the model represents enterprise data and the business rules that govern access to and updates of this data View -the view renders the contents of a model. It accesses enterprise data through the model and specifies how that data should be presented Controller - the controller translates interactions with the view into actions to be performed by the model

11 Design Patterns MVC – Class Diagram

12 Design Patterns MVC – Class Diagram controller view model

13 Behavior of the passive model

14 Behavior of the active model

15 A simple example

16 Another example

17 HTML form page Coffee Advisor> Coffee Advisor Select coffee Type: Milky Froffy Icey Spaced Out

18 Web.xml Coffee com.example.web.CoffeeSelect Coffee /SelectCoffee.do

19 Model class package com.example.model; import java.util.*; public class CoffeeExpert { public List getTypes(String type) { List types = new ArrayList(); if (type.equals("milky")) { types.add("latte"); types.add("cappuccino"); } else if (type.equals("froffy")) { types.add("latte"); types.add("cappuccino"); types.add("frappuccino"); }

20 else if (type.equals("icey")) { types.add("frappuccino"); } else if (type.equals("strong")) { types.add("espresso"); types.add("double espresso"); } else { types.add("Vending Machine"); } return(types); } }

21 Servlet controller public class CoffeeSelect extends HttpServlet { public void doPost( HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String c = request.getParameter("type"); // Now use our Coffee Model above CoffeeExpert ce = new CoffeeExpert(); List result = ce.getTypes(c); request.setAttribute("styles", result); RequestDispatcher view = request.getRequestDispatcher("result.jsp"); view.forward(request, response); } }

22 JSP view # Create the result.jsp file below Coffee Recommandation JSP View try: " + it.next()); } %>

23 J2EE Architechture Web tierEJB tierEIS tierClient tier

24 Client Tier The Client tier is the part the application that the user sees and interacts. The Client tier is responsible for: Presenting data to the user, interacting with the user Communicating with other tiers of the application using well-defined interfaces. A separate Client tier in the design provides flexibility and extensibility. Future new clients can be written using technologies or languages that do not yet even exist, since they must conform only to the interface for communicating with other tiers

25 Web Tier The Web tier is responsible for performing all Web-related processing, such as: serving HTML, formatting JSP pages for display by browsers. managing database connections.

26 EJB Tier Enterprise JavaBeans are components: Extend servers to perform application-specific functionality. hosts application-specific business logic and provides system-level services such as transaction management, concurrency control, and security. The interface between these components and their containers: Defined in the EJBs specification. Essentially, the EJBs tier provides a component model for access to distributed system services and persistent data.

27 Enterprise Information System (EIS) Tier The EIS tier is the enterprise information infrastructure. To ensure that data are consistent across application boundaries. Access to the EIS tier is usually transactional. Enterprise information systems provide the information infrastructure critical to the business processes of an enterprise. Examples of EISs include relational databases, enterprise resource planning (ERP) systems, mainframe transaction processing systems The EIS tier enforces security.

28 J2EE MVC Pattern Http request or post Response Forward Dispatch Update Extract Client browser Controller (action servlet) Business logic Model (server side JavaBean/EJB) View (JSP page)

29 MVC Structure for J2EE

30 Advantages of MVC pattern Separates Model from View: Implies separating internal data representation from presentation Easy to add multiple presentations of the same data Facilitates adding new types of presentation of data as per requirement. Model and View components can vary independently enhancing maintainability, extensibility, and testability.

31 Sapana Mehta (CS-6V81) Advantages of MVC design Pattern Separating Controller from View Permits run-time selection of an appropriate View based on user preference, or model state. Separating Controller from Model Allows configurable mapping of user actions on the Controller to application functions on the Model.

32 Drawbacks of the model Increased complexity Close coupling of views and controller to model Potential for excessive updates Close coupling between view and controller

33 THANK YOU..


Download ppt "MODEL VIEW CONTROLLER PATTERN. Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic."

Similar presentations


Ads by Google