Dive in Singleton Design Pattern
Dive in Singleton Design Pattern
Mammoth is a massively
multiplayer game research
framework.
mammoth.cs.mcgill.ca
The world of Mammoth is a 2D
environment viewed from a 2D
perspective.
The world contains a fixed
number of game objects, some
of which can be controlled by
humans (players).
A player can move around in the
game, examine objects, pick
them up, and drop them again.
Hans Vangheluwe and Alexandre Denault
IDs?
private Singleton() { }
private IdDistributor() {
this.lastId = -1;
}
public static IdDistributor getInstance() {
return IdDistributor.instance;
}
public long getId() {
this.lastId++;
return this.lastId;
}
}
Lazy Initialization
private Singleton() { }
return Singleton.instance;
}
}
Lazy Initialization (Better)
private Singleton() { }
return Singleton.instance;
}
}
Dsheet
Singleton