SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin
Agenda – Lecture 11a Review & renew. GoF Solutions to Exercise Set 9: PC-V-TS-G + Helper Solution to Exercise Set 8. GoF Composite, a second look. 8/20/2019 SOEN 343, © P.Chalin,
Redesigning Do-it-all TS (4 classes) Presentation Do-it-all Transaction Script Page Controller Template View redesign Transaction Script Domain Gateway Data Source 8/20/2019 SOEN 343, © P.Chalin,
Hello.jsp <%@ page contentType=“…" import=“…" %> <html> <% String fullName = (String) request.getAttribute("fullName"); %> <head><title>Hello</title></head> <body> <h1>Hello <%= fullName %>!</h1> </body> </html> 8/20/2019 SOEN 343, © P.Chalin,
Page Controller The doGet for this lecture’s solution is like the one presented last class except for: doGet(…) { … String fullName = GetNameTS.execute(ln); request.setAttribute(“fullName”, fullName); forward(“Hello.jsp”, request, response); } 8/20/2019 SOEN 343, © P.Chalin,
Using a Helper Class Why? Can hold several pieces of information to be used by the View. Can help decouple the View from, e.g. RDG. … 8/20/2019 SOEN 343, © P.Chalin,
Exercise Set 8 (for Igar et. al.) 8/20/2019 SOEN 343, © P.Chalin,
Relevant Code ViewTaskList processRequest(…) helper = new TaskListHelper(); ViewTaskListTS.execute(helper); request.setAttribute("helper", helper); forward("TaskManager.jsp", …); ViewTaskListTS execute(…) helper.setTaskList(TaskRDG.findAll()); 8/20/2019 SOEN 343, © P.Chalin,
ViewTaskList processRequest(…) TaskListHelper helper = new TaskListHelper(); try { ViewTaskListTS.execute(helper); } catch (Exception e) { helper.appendStatus(e.toString()); } if (helper.getTaskList() == null) { … } else { request.setAttribute("helper", helper); forward("TaskManager.jsp", request, response); 8/20/2019 SOEN 343, © P.Chalin,
ViewTaskListTS public static void execute(TaskListHelper helper) throws Exception { String msgHeader = "Total number of tasks: "; helper.setTaskList(TaskRDG.findAll()); DbRegistry.closeDbConnection(); helper.appendStatus(msgHeader + helper.getTaskList().size()); } 8/20/2019 SOEN 343, © P.Chalin,
Gang Of Four Gamma, Helm, Johnson, Vlissides SOEN 343, © P.Chalin, Erich 8/20/2019 SOEN 343, © P.Chalin,
Composite (Larman Section. 23.7) Context/problem How do you treat a group or composite structure of objects the same way (polymorphically) as a non-composite (atomic) object? Solution Define classes for composite and atomic objects so that they implement the same interface. 8/20/2019 SOEN 343, © P.Chalin,
Composite: Ex. Objects 8/20/2019 SOEN 343, © P.Chalin,
Composite: Ex. Class Diagram 8/20/2019 SOEN 343, © P.Chalin,
Must “add” be implemented by Line? In C++ add declared virtual; subclass need not implement it. In Java if add is abstract, then subclasses must implement it. String add(Graphic g) { throw new UnsupportedOperationException(); } Can you think of a better solution? 8/20/2019 SOEN 343, © P.Chalin,
Composite (Larman Section. 23.7) Context/problem How do you treat a group or composite structure of objects the same way (polymorphically) as a non-composite (atomic) object? Solution Define classes for composite and atomic objects so that they implement the same interface. 8/20/2019 SOEN 343, © P.Chalin,
Composite: Clients point-of-view 8/20/2019 SOEN 343, © P.Chalin,
Composite Pricing Strategies Interface Realization 8/20/2019 SOEN 343, © P.Chalin,
Composite 8/20/2019 SOEN 343, © P.Chalin,