Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 Agenda – Lecture 9a Review & renew. Midterm: clarifications.
Looking ahead. GoF: Singleton. EA Patterns Exercises 4/17/2019 SOEN 343, © P.Chalin,

3 Clarifications (Walid) Constructors cannot be static.
Constructors are not "inherited“ (Allen). Fields cannot be abstract. In the case of the P/C class example you can access the (non-static) field of in the parent class using the notation: super.of. The explicit call to super() is not necessary.  On the other hand, an explicit call to a super class constructor will be necessary if the default constructor of the parent is inaccessible (e.g. declared private) or if we want a constructor other than the non-default one to be invoked. 4/17/2019 SOEN 343, © P.Chalin,

4 Looking Ahead GRASP Gang-of-four (GoF).
Enterprise Application patterns. 4/17/2019 SOEN 343, © P.Chalin,

5 Gang Of Four Gamma, Helm, Johnson, Vlissides SOEN 343, © P.Chalin,
Erich 4/17/2019 SOEN 343, © P.Chalin,

6 GoF Pattern Summary (& Relationhips)
[Picutre (c) GoF CD] 4/17/2019 SOEN 343, © P.Chalin,

7 Design Issue: Ensure No More Than One Instance of a Class is Created
Given a class C, how can we ensure that only one instance of C is ever created? 4/17/2019 SOEN 343, © P.Chalin,

8 Converting C to a Singleton.
4/17/2019 SOEN 343, © P.Chalin,

9 Singleton Pattern Notice: Constructor is no longer public.
To access the instance use getUniqueInstance(). All other attribute and method declarations of C stay the same. 4/17/2019 SOEN 343, © P.Chalin,

10 «Singleton» C.getUniqueInstance()
public static C getUniqueInstance() { if(uniqueInstance == null) { uniqueInstance = new C(); } return uniqueInstance; 4/17/2019 SOEN 343, © P.Chalin,

11 Singleton: Design Alternatives/Issues
Create a class with static attributes and methods. Trade-offs: consider how easy the following are: Adapting the design so that x instances can be created (where x > 1). Subclassing. Passing the instance as a parameter. 4/17/2019 SOEN 343, © P.Chalin,

12 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 4/17/2019 SOEN 343, © P.Chalin,

13 Do-it-all Transaction Script
Presentation Do-it-all Transaction Script Domain Data Source 4/17/2019 SOEN 343, © P.Chalin,

14 Do-it-all Transaction Script, Class
public class DoItAllTS extends javax.servlet.http.HttpServlet { protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ... // } 4/17/2019 SOEN 343, © P.Chalin,

15 Redesigning This Application
Redisgn DoItAllTS 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. 4/17/2019 SOEN 343, © P.Chalin,

16 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(); String firstName = rs.getString("FirstName"); lastName.toUpperCase(); PrintWriter out = response.getWriter(); response.setContentType("text/html"); out.println("<h1>Hello "+firstName+" "+lastName+"</h1>"); 4/17/2019 SOEN 343, © P.Chalin,

17 Do-it-all Transaction Script 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. 4/17/2019 SOEN 343, © P.Chalin,

18 Redesigning Do-it-all TS (2 classes)
Presentation Do-it-all Transaction Script Page Controller (+ View) redesign Domain Table Module Data Source Note: “Page Controller (+ View)” is not an EA pattern but rather a combination of a Page Controller plus some functionality usually attributed to a view. 4/17/2019 SOEN 343, © P.Chalin,

19 Redesigning Do-it-all TS (2 classes)
Presentation Do-it-all Transaction Script Page Controller (+ View) redesign Domain Active Record Data Source 4/17/2019 SOEN 343, © P.Chalin,

20 Redesigning Do-it-all TS (3 classes)
Presentation Do-it-all Transaction Script Page Controller (+ View) redesign Transaction Script Domain Gateway Data Source G, a Gateway, can be either a TDG or an RDG 4/17/2019 SOEN 343, © P.Chalin,

21 Redesigning Do-it-all TS (4 classes)
Presentation Do-it-all Transaction Script Page Controller Template View redesign Transaction Script Domain Gateway Data Source 4/17/2019 SOEN 343, © P.Chalin,

22 Redesigning Do-it-all TS (4 classes)
Presentation Do-it-all Transaction Script Page Controller Template View redesign Person Mapper Person Domain [Pull out this slide in Fall 05] DbRegistry Data Source Since I added some domain logic to the sample code, this solution is no longer valid. 4/17/2019 SOEN 343, © P.Chalin,

23 Redesigning Do-it-all TS (5 classes)
Presentation Do-it-all Transaction Script Page Controller Template View redesign Transaction Script Person Domain Person Mapper Data Source Is there anything wrong with this design? (Hint: consider the dependencies and the layering style.) 4/17/2019 SOEN 343, © P.Chalin,

24 Redesigning Do-it-all TS (6 classes)
Presentation Do-it-all Transaction Script Page Controller Template View redesign Transaction Script Person Domain Person Mapper Table Data Gateway Data Source 4/17/2019 SOEN 343, © P.Chalin,

25 Presentation Domain Data Source EA Patterns Page Controller
Template View Presentation Front Controller Transform View Domain Model Transaction Script Domain Active Record Table Module Data Mapper Row Data Gateway Table Data Gateway Data Source 4/17/2019 SOEN 343, © P.Chalin,

26 Data Source Patterns Active Record is a Row Data Gateway + domain logic. Table Module is a Table Data Gateway + domain logic. Data Mapper maps Domain Model’s <---> database: Can either access the database itself, or Makes use of a Table Data Gateway. Does not contain Domain Logic (though it can be in the Domain Logic layer). 4/17/2019 SOEN 343, © P.Chalin,

27 Data Mapper Example (Tasks)
4/17/2019 SOEN 343, © P.Chalin,

28 Exercise Set 8 Answer Exercise Set 8 as you work through assignment 1
4/17/2019 SOEN 343, © P.Chalin,

29 Exercise Set 9 Setup: sit with your teammates.
Part I – do this on your own For each of the design solutions, fill in the grey boxes (representing classes in a class diagram) with a class name and/or pattern name. Part II – each member of the team chooses one of the design solutions and writes (a) A detailed class diagram for the solution. (b) The code for the solution. 4/17/2019 SOEN 343, © P.Chalin,


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

Similar presentations


Ads by Google