in reply to Inheritance and Container Classes and use/require

For how to use/require modules dynamically, see Best/possible ways to dynamically use modules. Once the module is loaded, it is retained in the appropriate namespace even if the use/require block goes out of scope: eg:
use strict; use Data::Dumper; my $obj = do_sub(); print Dumper $obj; my $cgi = new CGI; print Dumper $cgi; sub do_sub { use CGI; return new CGI; }
will result in no errors in the $cgi line.

As for what you have, you probably want to implement the so-called 'factory' class that you don't instantiate from, but instead use 'static' methods that creates your various subclass instances given the class name in addition to any data that they need. In the perl implementation, this need not necessarily be a separate class, but it's easier to set up this functionality in this fashion if you're not used to it.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Re: Inheritance and Container Classes and use/require
by TGI (Parson) on Jan 03, 2002 at 02:57 UTC

    Thanks for the great replies, everyone. Thanks to your help I was able to track down this node. Which goes into more detail on Factory classes.


    TGI says moo