Dando uma lida poraí sobre Design Patterns, vi dois exemplos interessantes de Singleton…Em Java
public class SingletonBobao{
private SingletonBobao(){}
public static SingletonBobao getSingletonBobao(){
if (ref == null) // ok, pode chamar o construtor
ref = new SingletonBobao();
return ref;
}
public Object clone() throws CloneNotSupportedException{
throw new CloneNotSupportedException();
}
private static SingletonBobao ref;
}
E em Ruby…
require 'singleton' class SingletonBobinho include Singleton end
Hummmmm…
Popularity: 23% [?]







