Ensure a class has only one instance, and provide a global point of access to it.
public class Singleton { private static Singleton uniqueInstance; //other useful instance variables here private Singleton() { } public static Singleton getInstance() { if (uniqueInstance == null) { uniqueInstance = new Singleton(); } return uniqueInstance; } //other useful methods here }
Where it can be used?
Printer
For logging
Holding Registry entry in single object.
No comments:
Post a Comment