The singleton is use to asegurate that only one instance of a class is
instantiated
Why ? Because is esential not have two or because there arent reason
for have two for example Factories, Loggers , ....
Example:
****************************************************
public class Registry {
//----------------------------------------------------------------------------
private Registry(){}
//----------------------------------------------------------------------------
private static Registry registry;
public static Registry getInstance(){
if (Registry.registry==null) Registry.registry = new Registry();
return Registry.registry;
}
public String doSomething(){.....}
// methods publics....
}
****************************************************
public class UseSingleton{
public UseSingleton(){
Registry.getInstance().doSomething();
}
}