[Israel.pm] Objects and classes

Mikhael Goikhman migo at homemail.com
Wed Jan 14 14:58:32 PST 2004


On 14 Jan 2004 22:13:16 +0000, Mikhael Goikhman wrote:
> 
> It is impossible to understand the class diagram from this page, but I
> would think there is some delegation mechanism in Apache::RequestRec
> (i.e. its' AUTOLOAD redirects unknown methods to other registered
> classes, like Apache::RequestIO). Another possible explanation is that
> Apache::RequestIO::import method adds Apache::RequestIO to the list of
> _superclasses_ of Apache::RequestRec using its @ISA, then the request
> object automatically gets more methods after loading this class:
> 
>   use Apache::RequestIO ();

Ok, since, Apache::RequestIO::import is not called when you load the
class using this syntax with empty parentheses, you may consider that
they don't use the second supposed way, aka dynamical superclassing.

The first way may still work. Apache::RequestRec::AUTOLOAD may query
$Apache::RequestIO::VERSION, and if it is defined, delegate a missing
method to this class. I am not sure why they didn't statically inherit
Apache::RequestRec from Apache::RequestIO in the first place. Probably
there is a good reason.

Anyway, just like inheritance, delegation is legitimate way to extend the
class functionality in languages supporting this.

In one of my projects I even dynamically _replace_ some class methods,
not just delegate/add new methods. This is needed to keep all legacy
scripts as is, but change some behaviour. The scripts would be called
then "perl -MClassReplacingSomeMethodsInOtherClass some_perl_script".
Such pragma technology may be useful for different purposes.

Regards,
Mikhael.
 
-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list