Below is a class using the singleton design pattern:
class Singleton
{
private static Singleton instance;
private Singleton()
{
...
}
public static synchronized Singleton getInstance()
{
if (instance == null)
instance = new Singleton();
return instance;
}
...
public void doSomething()
{
...
}
}
I wanted to know some design issues about the above class? Why is the instance variable instance
private and static. I understand that being private make the instance variable accessible only to object of that specific class but how does it help?