LogicalChaos has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to create a class hierarchy which, when new is called for the base class, the first parameter will allow a run time decision as to which derived class is required and instantiate that. Kind of like how DBI works. I would prefer to not specify all the classes required. Something like this:
rather than this:use Astro::Observation; my $obs = Astro::Observation->new( "simple", ... ); my $obc = Astro::Observation->new( "complex", ... );
I don't have a clue how to go about doing this. I have Conway's book, but cannot figure out from there.use Astro::Observation::Simple; use Astro::Observation::Complex; my $obs = Astro::Observation::Simple->new( ... ); my $obc = Astro::Observation::Complex->new( ... );
Can anyone suggest somewhere to look, or a pure perl module which uses this? I looked at DBI, but couldn't figure out how they accomplished this.
As you might be able to infer, this is my first attempt at using objects in Perl, and I'm barely treading water...
Thanks,
Rob
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Runtime instantiation decisions
by jeffa (Bishop) on Mar 30, 2002 at 17:01 UTC | |
|
Re: Runtime instantiation decisions
by Kanji (Parson) on Mar 30, 2002 at 17:02 UTC | |
by merlyn (Sage) on Mar 30, 2002 at 18:29 UTC | |
by LogicalChaos (Beadle) on Mar 30, 2002 at 19:01 UTC | |
|
Re: Runtime instantiation decisions
by LogicalChaos (Beadle) on Mar 30, 2002 at 18:37 UTC |