SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin
Agenda – Lecture 11a GRASP interrelationships. Dice Game Test class: a solution. GoF (Simple) Factory Singleton 1/17/2019 SOEN 343, © P.Chalin,
GRASP Information Expert Creator High Cohesion Low Coupling Controller Polymorphism Pure Fabrication Indirection Protected Variations 1/17/2019 SOEN 343, © P.Chalin,
GRASP: Interrelationships This is how Larman illustrates the interrelationships between the GRASP. 1/17/2019 SOEN 343, © P.Chalin,
Dice Game Test Class: A Solution (Given in class) 1/17/2019 SOEN 343, © P.Chalin,
Gang Of Four Gamma, Helm, Johnson, Vlissides SOEN 343, © P.Chalin, Erich 1/17/2019 SOEN 343, © P.Chalin,
GoF Pattern Summary (& Relationhips) [Picutre (c) GoF CD] 1/17/2019 SOEN 343, © P.Chalin,
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? 1/17/2019 SOEN 343, © P.Chalin,
Converting C to a Singleton. 1/17/2019 SOEN 343, © P.Chalin,
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. 1/17/2019 SOEN 343, © P.Chalin,
«Singleton» C.getUniqueInstance() public static C getUniqueInstance() { if(uniqueInstance == null) { uniqueInstance = new C(); } return uniqueInstance; 1/17/2019 SOEN 343, © P.Chalin,
Thread-safe Creation Method public static synchronized C getUn…() { … } 1/17/2019 SOEN 343, © P.Chalin,
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. … (See Larman05, Section 26.5) 1/17/2019 SOEN 343, © P.Chalin,
Singleton: Design Issues (Cont’d) See Larman05, Section 26.5 for discussion of Design trade-offs, including eager/lazy evaluation of Singleton.uniqueInstance see. 1/17/2019 SOEN 343, © P.Chalin,
Singleton & UML 1/17/2019 SOEN 343, © P.Chalin,
Singleton & UML Larman05, fig. 1/17/2019 SOEN 343, © P.Chalin,