Hello Frank,
If you really absolutely need to do that there are ways and you may be
interested to look at the following two Reflection APIs:
- Class.forName
- Proxy.newProxyInstance
BUT I would seriously object the need to use this mechanism at
application level outside of a framework: there are cleaner alternatives for
an application e.g. how about a map of Factory instances keyed by some
ID that is read from your XML? so your application create instances that
that specified through configuration hmmm sounds like IoC to me.
Well anyway you can find an example of the Proxy.newProxyInstance here:
http://perfectjpattern.svn.sourcefo...ructural/composite/Composite.java?view=markup
The idea is: you give me an interface Class type that you may create
from a String loaded from an XML file see Class.forName, and I
give you a dynamic instance (implementation) of such interface.
I managed to componentize (or make a component out of) the Composite
Design Pattern that way. It is almost exactly the same mechanism as the
Mock objects use for testing.
HTH,
Giovanni