jkeenan1 has asked for the wisdom of the Perl Monks concerning the following question:
"this approach discourages messing about with class hierarchies at run time, by reassigning @ISA. The temptation to modify @ISA at run time is usually a sign that your class might be better implemented as a factory, a façade, or with some other meta-object technique. (Emphasis added.)
Atypically, Damian doesn't provide an example of the code that would implement one of those other techniques. Not being experienced in design patterns, I'm somewhat at sea here. So I'm wondering if someone could provide a simple example of, say, the alternative to something like this:
BEGIN { use vars qw ( $VERSION @ISA ); $VERSION = '0.01'; require Solar::Data; require Lunar::Data; push @ISA, qw( Solar::Data Lunar::Data ); };
And later, at run time ...
if ($sun_rises_in_west) { require Astrological::Data; unshift @ISA, Astrological::Data; }
... called because, under certain unusual conditions, I want to make sure that the inheritance mechanism finds an Astrological::Data method (say, get_sunrise_time) before it finds Solar::Data::get_sunrise_time().
What would the alternative approach look like in code? Why, particularly in a simple case, would it be superior?
Thank you very much.
Jim Keenan
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modification of @ISA at run time
by TheDamian (Vicar) on Sep 01, 2005 at 06:50 UTC | |
by jkeenan1 (Deacon) on Sep 01, 2005 at 12:30 UTC | |
by jkeenan1 (Deacon) on Sep 02, 2005 at 04:02 UTC | |
|
Re: Modification of @ISA at run time
by nothingmuch (Priest) on Sep 01, 2005 at 07:04 UTC | |
by xdg (Monsignor) on Sep 01, 2005 at 14:02 UTC | |
by nothingmuch (Priest) on Sep 01, 2005 at 14:20 UTC | |
by blazar (Canon) on Sep 01, 2005 at 14:59 UTC | |
by nothingmuch (Priest) on Sep 01, 2005 at 15:36 UTC | |
| |
|
Re: Modification of @ISA at run time
by pg (Canon) on Sep 01, 2005 at 04:51 UTC | |
|
Re: Modification of @ISA at run time
by gargle (Chaplain) on Sep 01, 2005 at 06:14 UTC | |
|
Re: Modification of @ISA at run time
by mkirank (Chaplain) on Sep 01, 2005 at 06:04 UTC |