Re: newbie java design question
- From: "Thomas Fritsch" <i.dont.like.spam@xxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 20:06:13 +0200
"Matt Rose" <matt.rose.at@xxxxxxxxx> wrote:
If you're not using something like Spring, (or even if you are!) you
could reflect the class.
Something along the lines of:
//read the fully qualified classname from your config file into
AImplClassName
Class aImpl = Class.forName(AImplClassName);
Constructor[] constructors = aImpl.getConstructors();
//Choose which constructor you want to invoke, create an Object[] with
the arguments for it called args
A a = (A) chosenConstructor.newInstance(args);
return a;
If the implementation classes have a no-arguments constructor, this can be
simplified even further:
A a = (A) Class.forName(AImplClassName).newInstance();
return a;
--
Thomas
.
- References:
- newbie java design question
- From: bob_roberts
- Re: newbie java design question
- From: Matt Rose
- newbie java design question
- Prev by Date: Re: Speeding up URLConnection
- Next by Date: Re: JScrollPane Scrollbar issues
- Previous by thread: Re: newbie java design question
- Next by thread: Re: newbie java design question
- Index(es):