
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

































Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 — Lecture 21 — 11/04/ VOTE! © University of Colorado, 2008
static getInstance() : Singleton private Singleton() static my_instance : Singleton
4
1 public class Singleton { 2 3 private static Singleton uniqueInstance; 4 5 private Singleton() {} 6 7 public static Singleton getInstance() { 8 if (uniqueInstance == null) { 9 uniqueInstance = new Singleton(); 10 } 11 return uniqueInstance; 12 } 13 } 14
7
10
1 public class Singleton { 2 3 private static Singleton uniqueInstance; 4 5 private Singleton() {} 6 7 public static synchronized Singleton getInstance() { 8 if (uniqueInstance == null) { 9 uniqueInstance = new Singleton(); 10 } 11 return uniqueInstance; 12 } 13 14 } 15
action() Receiver setCommand() Invoker execute() undo() Command execute() undo() ConcreteCommand public void execute() { receiver.action() }
13