Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.

Similar presentations


Presentation on theme: "SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin."— Presentation transcript:

1 SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin

2 Agenda – Lecture 10a Review & renew. Controller Patterns
GRASP EA: Page and Front Controllers. A Spectrum of Web EA alternate designs. 12/1/2018 SOEN 343, © P.Chalin,

3 GRASP: Controller Who handles a system event?
E.g. “List Movies” Main choices: assign to a design entity representing Overall system, or subsystem (façade controller). A Use Case scenario (often named, e.g. ListMovieHandler). 12/1/2018 SOEN 343, © P.Chalin,

4 GRASP: Controller Who handles a system event?
E.g. “List Movies” Main choices: assign to a design entity representing Overall system, or subsystem (façade controller). A Use Case scenario (often named, e.g. ListMovieHandler). 12/1/2018 SOEN 343, © P.Chalin,

5 Presentation Domain Data Source Controller Patterns Page Controller
Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Data Mapper Active Record Table Module Data Mapper Row Data Gateway Table Data Gateway Data Source Table Data Gateway 12/1/2018 SOEN 343, © P.Chalin,

6 Page Controller 12/1/2018 SOEN 343, © P.Chalin,

7 A1 Page Controllers protected void processRequest(
HttpServletResponse response) throws ServletException, java.io.IOException // { TaskListHelper helper = new TaskListHelper(); try { ViewTaskListTS.execute(helper); } catch (Exception e) { helper.appendStatus(e.toString()); } if (helper.getTaskList() == null) { request.setAttribute("errorMessage", helper.getStatus()); forward("Error.jsp", request, response); } else { request.setAttribute("helper", helper); forward("TaskManager.jsp", request, response); 12/1/2018 SOEN 343, © P.Chalin,

8 A1 Page Controllers protected void processRequest(…) throws … {
TaskListHelper helper = new TaskListHelper(); try { ViewTaskListTS.execute(helper); } catch (Exception e) { helper.appendStatus(e.toString()); } if (helper.getTaskList() == null) { request.setAttribute("errorMessage", helper.getStatus()); forward("Error.jsp", request, response); } else { request.setAttribute("helper", helper); forward("TaskManager.jsp", request, response); 12/1/2018 SOEN 343, © P.Chalin,

9 Page Controller vs. Front Controller – Differences in URL
12/1/2018 SOEN 343, © P.Chalin,

10 Page Controllers for A1 http:/stu.cs/343A1/ViewTaskList
12/1/2018 SOEN 343, © P.Chalin,

11 Front Controller for A1 Base URL: http:/stu.cs/343A1/frontController
…/frontController ?command=ViewTaskList …/frontController ?command=AddTaskGrade&title=abc&… 12/1/2018 SOEN 343, © P.Chalin,

12 Front Controller 12/1/2018 SOEN 343, © P.Chalin,

13 Front Controller 12/1/2018 SOEN 343, © P.Chalin,

14 Front Controller (Fowler) Command (GoF) Patterns
FrontCommand + init ( ) + processRequest ( ) RemoveStudentCommand ViewStudInfoCommand + processRequest ( ) + processRequest ( ) 12/1/2018 SOEN 343, © P.Chalin,

15 Front Controller: Sequence Diagram
12/1/2018 SOEN 343, © P.Chalin,

16 Front Controller: ProcessRequest
12/1/2018 SOEN 343, © P.Chalin,

17 Front Controller (cont’d)
12/1/2018 SOEN 343, © P.Chalin,

18 Front Controller: Advantages?
12/1/2018 SOEN 343, © P.Chalin,

19 Web EA Redesign Exercise
Refactoring a DoItAll Servlet, let me count the ways … 12/1/2018 SOEN 343, © P.Chalin,

20 Do-it-all Servlet or Script
Presentation Do-it-all Servlet or Script Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

21 Do-it-all Servlet or Script, Class
public class DoItAll extends javax.servlet.http.HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ... // } 12/1/2018 SOEN 343, © P.Chalin,

22 Redesigning This Application
Redesign DoItAll so as to increase the class cohesion. Create new classes. Which EA patterns would you use? Distribute the doGet() method code (given on the next slide) into the new classes. Identify which lines would go into which classes. 12/1/2018 SOEN 343, © P.Chalin,

23 Do-it-all Transaction Script, doGet()
String lastName = request.getParameter(“…"); Connection dbc = DbRegistry.getDbConnection(); String findSql = "SELECT * from … where LastName = ?”; PreparedStatement dbQuery = dbc.prepareStatement(findSql); dbQuery.setString(1, lastName); ResultSet rs = dbQuery.executeQuery(); rs.next(); String firstName = rs.getString("FirstName"); lastName = lastName.toUpperCase(); PrintWriter out = response.getWriter(); response.setContentType("text/html"); out.println("<h1>Hello "+firstName+" "+lastName+"</h1>"); 12/1/2018 SOEN 343, © P.Chalin,

24 Do-it-all Servlet Redesign: Separating Concerns
The next few slides show ways in which we can separate concerns; i.e. distribute the functionality of the do-it-all script into separate classes. Combinations other than the ones shown are possible. 12/1/2018 SOEN 343, © P.Chalin,

25 Redesigning Do-it-all (2 classes) [#1]
Presentation Do-it-all redesign Domain Data Source Note: 12/1/2018 SOEN 343, © P.Chalin,

26 Redesigning Do-it-all (3 classes) [#3]
Presentation Do-it-all redesign Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

27 Redesigning Do-it-all (4 classes) [#4]
Presentation Do-it-all redesign Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

28 Redesigning Do-it-all : Adding … (5 classes) [#5]
Presentation Do-it-all redesign Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

29 Redesigning Do-it-all : Adding … [#5b]
Presentation Do-it-all redesign Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

30 Redesigning Do-it-all (5 classes) [#5c]
Presentation Do-it-all redesign Domain Data Source Is there anything wrong with this design? (Hint: consider the dependencies and the layering style.) 12/1/2018 SOEN 343, © P.Chalin,

31 Redesigning Do-it-all (6 classes) [#6]
Presentation Do-it-all redesign Domain Data Source 12/1/2018 SOEN 343, © P.Chalin,

32 Enterprise Application Patterns (v1.3)
Page Controller Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Data Mapper Active Record Table Module Data Mapper Row Data Gateway Table Data Gateway Data Source Table Data Gateway 12/1/2018 SOEN 343, © P.Chalin,


Download ppt "SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin."

Similar presentations


Ads by Google