Is it a good idea using classloaders in Factory methods or builders to
select the class to instantanate? Something *like*:
class Factory {
private Classloader ldr = Factory.class.getClassLoader();
AnInterface getAnObject(String classname) {
if (isClassNameValid(classname)) {
Class cls = ldr.loadClass(classname);
return (AnInterface)(cls.newInstance());
} else {
throw new AppropiateException();
} // end else
} // end function
} // end class
Of course, there's more than that needed (even to compile). But is the
general pattern a good idea? Are there any pitfalls or warnings
involved with that kind of design?
--
Jimmy Cerra
http://nemo.dev.java.net
] ===========================================
] "my mind is slipping away...
] ...day by glorious day"
] Robin Gorkin
] ===========================================