Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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:

Factory
A class that generates instances of other classes, choosing which class to build on the basis of run-time information.
Façade
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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-10-30 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls