ph page 18-24 gof singleton p. 127-134

7
PH page 18-24 GoF Singleton p. 127-134 Emanuel Ekstrom

Upload: laith-lopez

Post on 31-Dec-2015

20 views

Category:

Documents


2 download

DESCRIPTION

PH page 18-24 GoF Singleton p. 127-134. Emanuel Ekstrom. Orphans & Adoption. Context: Making a file system. Three objects: Node, File, Directory. Why do we need to adopt? Why do we need to orphan? Who gets an adopt/orphan interface? So are they all the same?. Singleton. Intent: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: PH page 18-24 GoF Singleton p. 127-134

PH page 18-24GoF Singleton p. 127-134

Emanuel Ekstrom

Page 2: PH page 18-24 GoF Singleton p. 127-134

Orphans & Adoption

Context: Making a file system. Three objects: Node, File, Directory.

Why do we need to adopt? Why do we need to orphan? Who gets an adopt/orphan interface? So are they all the same?

Page 3: PH page 18-24 GoF Singleton p. 127-134

Singleton

Intent:

”Ensure a class only has one instance, and provide a global point of access to it.”

Page 4: PH page 18-24 GoF Singleton p. 127-134

Discussion

Who needs only one instance?

What is good about a global access point?

Why not global variables instead?

Page 5: PH page 18-24 GoF Singleton p. 127-134

How do we make a Singleton? (GoF p. 131) Constructor protected Public static Instance() function.

Is this enough?

Page 6: PH page 18-24 GoF Singleton p. 127-134

Discussion

What if we want to delete a Singleton?

What if a deleted Singleton is called?

Is there a solution to the problem?

Page 7: PH page 18-24 GoF Singleton p. 127-134

Subclassing

Problem: Making sure the subclasses are unique and that the clients can access it.

How is this solved?

Drawbacks?