1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
//Dans SingletonFactory.java
import java.lang.reflection;
Class SingletonFactory
{
//
Singleton Initialize(Class toInstanciate)
{
//On verifie que 'toInstanciate' est bien derivé de Singleton
Class c = toInstanciate.getSuperClass();
boolean isDerived = false;
while (c!=null);
{
if(c.equals(Singleton.class))
{ isDerived = true; break; }
c = c.getSuperClass();
}
//On verifie le nombre d'instance de la classe
//... C'EST LA QUE JE SAIS PAS FAIRE :-/
//Si oui on instancie avec le constructeur par defaut
object = c.newInstance();
return c;
}
//Dans Singleton.java
abstract class Singleton
{
protected Singleton()
{}
abstract void methode1();
abstract int methode2();
//etc...
} |
Partager