What is being described here is actually the Singleton
pattern and is used in many situations.
The singleton pattern ensures that there is only one instance of a class and provides a global point of access to that instance of the class.
Example: A window manager inside your application, a database connection pool, print spooler, serial communication, etc.
public class PrintSpooler {
private static PrintSpooler spooler;
private PrintSpooler(){}
public static synchronized PrintSpooler getPrintSpooler() {
if (spooler == null)
spooler = new PrintSpooler();
return spooler;
}
}
In the above example you don't need to worry if the instance has been created, the class handles this for you and you can be sure you always uses the same instance.
Thomas De Vos
http://www.javacertificate.com