Download presentation
Presentation is loading. Please wait.
Published byKai Hyttinen Modified over 5 years ago
1
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin
2
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,
3
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,
4
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,
5
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,
6
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,
7
Exercise Set 8 (for Igar et. al.)
8/20/2019 SOEN 343, © P.Chalin,
8
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,
9
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,
10
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,
11
Gang Of Four Gamma, Helm, Johnson, Vlissides SOEN 343, © P.Chalin,
Erich 8/20/2019 SOEN 343, © P.Chalin,
12
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,
13
Composite: Ex. Objects 8/20/2019 SOEN 343, © P.Chalin,
14
Composite: Ex. Class Diagram
8/20/2019 SOEN 343, © P.Chalin,
15
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,
16
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,
17
Composite: Clients point-of-view
8/20/2019 SOEN 343, © P.Chalin,
18
Composite Pricing Strategies
Interface Realization 8/20/2019 SOEN 343, © P.Chalin,
19
Composite 8/20/2019 SOEN 343, © P.Chalin,
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.