Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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>

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]
[erix]: bullfinch ( a male and a female )
erix learned the word 'portaging' not so long ago (from vikings lugging their ships from one river-system to another)
[choroba]: my best run so far
[erix]: I think they build a portaging installation for yachts here not so long ago - lemme google it
[erix]: choroba ah, you should have sprinted 7 s off that :)
[erix]: (but then there's always a next (im)possible goal)
Corion avoids running by starting on time
[choroba]: my phone showed me 1 hour 10 km which was my goal, it changed a bit after uploading to the website

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-05-24 12:48 GMT
Find Nodes?
    Voting Booth?