COMP9321 Web Application Engineering Semester 2, 2016 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 7 1COMP9321, 16s2, Week 7 http://webapps.cse.unsw.edu.au/webcms2/course/index.php?cid=2445 Design Patterns 2COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Design Patterns 3COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. Design Patterns 4COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. A design pattern represents a solutions to problems that arise when developing a software. Design Patterns 5COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. A design pattern represents a solutions to problems that arise when developing a software. Design pattern are granular and applied at different levels such as: Frameworks Subsystems Sub-subsystems Design Patterns 6COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. A design pattern represents a solutions to problems that arise when developing a software. Design pattern are granular and applied at different levels such as: Frameworks Subsystems Sub-subsystems Categories include: Design Architectural Analysis Creational Structural Behavioral Design Patterns 7COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. A design pattern represents a solutions to problems that arise when developing a software. Design pattern are granular and applied at different levels such as: Frameworks Subsystems Sub-subsystems Categories include: Design Architectural Analysis Creational Structural Behavioral MVC: Model View Controllere.g. Design Patterns 8COMP9321, 16s2, Week 7 A pattern is a proven solution to a problem in a context. Each pattern expresses a relation between a certain context, a problem, and a solution. A design pattern represents a solutions to problems that arise when developing a software. Design pattern are granular and applied at different levels such as: Frameworks Subsystems Sub-subsystems Categories include: Design Architectural Analysis Creational Structural Behavioral Gamma et al (Gang of Four) produced a famous book which listed 23 “Design” patterns J2EE Design Patterns 9COMP9321, 16s2, Week 7 J2EE Design Patterns 10COMP9321, 16s2, Week 7 Web Application Architecture 11COMP9321, 16s2, Week 7 Web Application Architecture 12COMP9321, 16s2, Week 7 Web Application Architecture 13COMP9321, 16s2, Week 7 Web Application Architecture 14COMP9321, 16s2, Week 7 Web Application Architecture 15COMP9321, 16s2, Week 7 Web Application Layers 16COMP9321, 16s2, Week 7 J2EE design guidelines: Web tier 17COMP9321, 16s2, Week 7 J2EE design guidelines: Web tier 18COMP9321, 16s2, Week 7 Servlet Design Guidelines 19COMP9321, 16s2, Week 7 Servlet design guidelines: When to use Servlets 20COMP9321, 16s2, Week 7 Servlet design guidelines: When to use Servlets 21COMP9321, 16s2, Week 7 JSP Design Guidelines 22COMP9321, 16s2, Week 7 http://www.oracle.com/technetwork/articles/java/servlets-jsp-140445.html JSP Design Guidelines 23COMP9321, 16s2, Week 7 JSP Design Guidelines 24COMP9321, 16s2, Week 7 JSP Design Guidelines 25COMP9321, 16s2, Week 7 Include directive includes the file at translation time; whereas the include action includes the file at runtime. JSP Design Guidelines 26COMP9321, 16s2, Week 7 JSP Design Guidelines 27COMP9321, 16s2, Week 7 JSP Design Guidelines 28COMP9321, 16s2, Week 7 General Guideline for Servlet/JSP/JavaBeans 29COMP9321, 16s2, Week 7 General Guideline for Servlet/JSP/JavaBeans 30COMP9321, 16s2, Week 7 General Guideline for Servlet/JSP/JavaBeans 31COMP9321, 16s2, Week 7 Structuring Web applications Architectural Patterns (MVC) 32COMP9321, 16s2, Week 7 Structuring Web applications 33COMP9321, 16s2, Week 7 Structuring Web applications 34COMP9321, 16s2, Week 7 Structuring Web applications 35COMP9321, 16s2, Week 7 Model 1 Example 36COMP9321, 16s2, Week 7 Model 1 Example 37COMP9321, 16s2, Week 7 Model 1 Example 38COMP9321, 16s2, Week 7 Model 1 Example 39COMP9321, 16s2, Week 7 Model 1 Example 40COMP9321, 16s2, Week 7 Model 1 Example 41COMP9321, 16s2, Week 7 Model 1 Architecture 42COMP9321, 16s2, Week 7 MVC Model View Controller 43COMP9321, 16s2, Week 7 Model 2 Architecture = MVC pattern 44COMP9321, 16s2, Week 7 Model 2 Architecture = MVC pattern 45COMP9321, 16s2, Week 7 MVC Components and Roles 46COMP9321, 16s2, Week 7 MVC can be broken down into three elements: Model - The model represents data and the rules that govern access to and updates of this data. View - The view renders the contents of a model. It specifies exactly how the model data should be presented. Controller - The controller translates the user's interactions with the view into actions that the model will perform. http://www.oracle.com/technetwork/articles/javase/index-142890.html MVC Components and Roles 47COMP9321, 16s2, Week 7 http://www.oracle.com/technetwork/articles/javase/index-142890.html Model 2 Architecture = MVC pattern 48COMP9321, 16s2, Week 7 Model 2 Architecture = MVC pattern 49COMP9321, 16s2, Week 7 Model 2 Architecture = MVC pattern 50COMP9321, 16s2, Week 7 Model 2 Architecture = MVC pattern 51COMP9321, 16s2, Week 7 Case for a centralised controller 52COMP9321, 16s2, Week 7 Case for a centralised controller 53COMP9321, 16s2, Week 7 Case for multiple controllers 54COMP9321, 16s2, Week 7 FrontController Pattern 55COMP9321, 16s2, Week 7 FrontController Pattern 56COMP9321, 16s2, Week 7 • The Front Controller pattern is a software design pattern. • The pattern relates to the design of web applications. • It provides a centralized entry point for handling requests. • Front controllers are often used in web applications to implement workflows. • The front controller may be implemented as a Java object. FrontController Pattern 57COMP9321, 16s2, Week 7 • The Front Controller pattern is a software design pattern. • The pattern relates to the design of web applications. • It provides a centralized entry point for handling requests. • Front controllers are often used in web applications to implement workflows. • The front controller may be implemented as a Java object. FrontController implementation: Command Design Pattern 58COMP9321, 16s2, Week 7 Command Design Pattern 59COMP9321, 16s2, Week 7 Command Design Pattern 60COMP9321, 16s2, Week 7 Command Design Pattern 61COMP9321, 16s2, Week 7 Command Design Pattern 62COMP9321, 16s2, Week 7 Command Design Pattern 63COMP9321, 16s2, Week 7 Command Design Pattern 64COMP9321, 16s2, Week 7 Command Design Pattern 65COMP9321, 16s2, Week 7 Command Design Pattern 66COMP9321, 16s2, Week 7 Command Design Pattern 67COMP9321, 16s2, Week 7 Command Design Pattern 68COMP9321, 16s2, Week 7 Command Design Pattern 69COMP9321, 16s2, Week 7 Identifying the Command Pattern in the phonebook lab 70COMP9321, 16s2, Week 7 Implementing the Command Pattern 71COMP9321, 16s2, Week 7 Typical "Assignment 2" Architecture 72COMP9321, 16s2, Week 7 Next Week 73COMP9321, 16s2, Week 7 References 74COMP9321, 16s2, Week 7 • Core J2EE patterns, Deepak Alur, John Crupi and Dan Marlks, Prentice Hall • Patterns of Enterprise Application Architecture, Martin Fowler, Addison-Wesley • http://java.sun.com/blueprints/patterns/ • http://www.oracle.com/technetwork/articles/javase/index-142890.html 75COMP9321, 16s2, Week 7