Considere o trecho de código ilustrado a seguir:
public class Highlander{
private static Highlander instance = null;
private Highlander(){
}
public static Highlander getInstance(){
if (instance==null){
instance = new Highlander();
}
return instance;
}
public int soma(int x, int y){
return x+y;
}
}
private Highlander(){
}
public static Highlander getInstance(){
if (instance==null){
instance = new Highlander();
}
return instance;
}
public int soma(int x, int y){
return x+y;
}
}
O trecho de código em questão ilustra uma implementação do padrão de projeto: