[Israel.pm] Objects and classes

Mikhael Goikhman migo at homemail.com
Wed Jan 14 14:13:16 PST 2004


On 14 Jan 2004 21:22:18 +0200, semuel wrote:
> 
> I must confess: I never did learned seriously the OO implementation in
> perl. I am familiar with C++ and Java's, and just assumed that it's
> basically the same.

You should read "perldoc perltoot" man page if you are not familar with
the Perl OO model.

> But in these languages, when you subclass, the new
> class have a name of its own. It does not populate the superior class
> name space, but have its own name space.  So you say that in perl
> subclasses lives in their superior class name space.

No, this is not usually the case. Inheritance is inheritance regardless
of the language.

It is just that Perl is much more flexible than any of these other
languages, so it does not limit you to static paradigms. If it makes
sence to enhance the name space of other classes, then this may be done.
This paradigm is not called inheritance though. Delegation or dynamism
maybe, something that statical languages like C++ and Java miss.

I think that the Yuval's answer caused your confusion. He suggested that
Apache::RecquestIO inherits from Apache::RequestRec, just like IO::File
inherits from IO::Handle. I am not a big Apache programmer, but this page
hints that Apache::RequestIO does not inherit from Apache::RequestRec:

  http://perl.apache.org/docs/2.0/api/Apache/RequestIO.html

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 ();

Of course, I didn't see the mod_perl sources, and its documentation is
incomplete, so I can only guess about the implementation details.

Hey, in Ruby you may even automatically change the class inheritance
of a single object, not just the whole class. Now this is a dynamism. :)

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'
ruby -e '"d9b815c07f9b8d1e".scan(/./){|c|putc 64+c.hex}'



More information about the Perl mailing list