Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Modification of @ISA at run time

by TheDamian (Priest)
on Sep 01, 2005 at 06:50 UTC ( #488309=note: print w/ replies, xml ) Need Help??

in reply to Modification of @ISA at run time

First some definitions:

A class that generates instances of other classes, choosing which class to build on the basis of run-time information.
A class that acts as a front-end for one or more other classes, delegating the actual work to those classes as appropriate.

In your particular example, what you want is a factory: a class that generates objects according to where the sun rises. For example:

# Rational helper class... package Astro::Data::Scientific; use base Solar::Data; use base Lunar::Data; # <define methods here> # "Differently rational" helper class... package Astro::Data::Mythological; use base Astrological::Data; # Pre-empt normal methods use base Astro::Data::Scientific; # <overload any methods here that the # heavens dictate should behave differently> # Factory class... package Astro::Data; # Constructor returns instances of helper classes, # depending on run-time astro[nl]o[mg]ical conditions sub new { shift; # off class name if ($sun_rises_in_west) { return Astro::Data::Mythological->new(@_); } else { return Astro::Data::Scientific->new(@_); } } # <no methods of its own, since it's never actually instantiated>

Comment on Re: Modification of @ISA at run time
Download Code
Replies are listed 'Best First'.
Re^2: Modification of @ISA at run time
by jkeenan1 (Deacon) on Sep 01, 2005 at 12:30 UTC
    Thanks, Damian and all the others who took the time to reply.

    I think I was mostly thrown by the unfamiliar nomenclature. It turns out that I've already used the factory concept (in projects other than the current one) without knowing the fancy name. So I shouldn't have too much trouble implementing one now.

    Jim Keenan

Re^2: Modification of @ISA at run time
by jkeenan1 (Deacon) on Sep 02, 2005 at 04:02 UTC
    Here is a cleaned-up version of Damian's example, along with a test.

    I hope this example is (a) correct and (b) useful to the next person who wonders about this.

    Jim Keenan

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://488309]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2015-11-29 18:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (752 votes), past polls