Like for Singleton pattern
, we manage and create only 1 instance.
now for suppose class Abc
, i just want to
1.) create only 3 instances at maximum.
2.) Multithreading environment.
class Abc{
private static Abc abc1;
private static Abc abc2;
private static Abc abc3;
private Abc(){
}
public static synchronized Abc getInstance1(){
if(abc1 == null){
abc1 = new Abc();
}
return abc1;
}
: // same as above for abc2
: // same as above for abc3
}
** Now problem is suppose i want to increase instance from total 3 to to say 4 or 5 or n number.
Also i do want to expose so many methods (getInstance1(), getInstance2()... etc)
Aucun commentaire:
Enregistrer un commentaire