Download presentation
Presentation is loading. Please wait.
Published byYuliana Darmali Modified over 6 years ago
1
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin
2
Agenda – Lecture 11a GRASP interrelationships.
Dice Game Test class: a solution. GoF (Simple) Factory Singleton 1/17/2019 SOEN 343, © P.Chalin,
3
GRASP Information Expert Creator High Cohesion Low Coupling Controller
Polymorphism Pure Fabrication Indirection Protected Variations 1/17/2019 SOEN 343, © P.Chalin,
4
GRASP: Interrelationships
This is how Larman illustrates the interrelationships between the GRASP. 1/17/2019 SOEN 343, © P.Chalin,
5
Dice Game Test Class: A Solution
(Given in class) 1/17/2019 SOEN 343, © P.Chalin,
6
Gang Of Four Gamma, Helm, Johnson, Vlissides SOEN 343, © P.Chalin,
Erich 1/17/2019 SOEN 343, © P.Chalin,
7
GoF Pattern Summary (& Relationhips)
[Picutre (c) GoF CD] 1/17/2019 SOEN 343, © P.Chalin,
8
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,
9
Converting C to a Singleton.
1/17/2019 SOEN 343, © P.Chalin,
10
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,
11
«Singleton» C.getUniqueInstance()
public static C getUniqueInstance() { if(uniqueInstance == null) { uniqueInstance = new C(); } return uniqueInstance; 1/17/2019 SOEN 343, © P.Chalin,
12
Thread-safe Creation Method
public static synchronized C getUn…() { … } 1/17/2019 SOEN 343, © P.Chalin,
13
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,
14
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,
15
Singleton & UML 1/17/2019 SOEN 343, © P.Chalin,
16
Singleton & UML Larman05, fig. 1/17/2019 SOEN 343, © P.Chalin,
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.