Constructor Class
Today I was trying to create na standard Factory design pattern to a bunch of classes that I created. Using JAVA reflection classes I have designed some cool stuff:
protected IGenClass createObject (Class objClass) throws NoSuchMethodException, Exception{
Constructor constructors = null;
try {
constructors = objClass.getConstructor();
}catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return constructors.newInstance(sIndividual);
}
In this simple case would be the same that wrote the code
IGenClass obj = new ImplGenClass();
I know this is not a great thing, but use some imagination, this can be a great thing to make easy to create a bunch of factories.
I hope this can be useful.
-
Arquivos
- Dezembro 2008 (2)
- Novembro 2008 (5)
- Agosto 2008 (1)
- Abril 2008 (2)
- Novembro 2007 (2)
- Setembro 2007 (1)
- Agosto 2007 (4)
-
Categorias
-
RSS
Entradas RSS
Comentários RSS