Everything2
Near Matches
Ignore Exact
Full Text
Everything2

@ISA

created by ariels

(thing) by ariels (21.4 hr) (print)   ?   (I like it!) Mon May 21 2001 at 11:34:33

Perl mechanism for (multiple!) inheritance (pronounced "is-a", after standard object oriented programming terminology).

An object in Perl is merely a reference that has been blessed into a package. If $a holds an object, $a->meth(arguments...) calls that object's meth method.

Assume $a was blessed into package A. Then A::meth($a, arguments...) will be called. But what if no sub A::meth exists?

Perl doesn't give up, not yet. If there's a (global) variable @A::ISA, Perl will loop over its elements and treat each one as a package name (a string). For a name parent, it will attempt to find a method meth as if $a were in fact blessed to package parent.

You can explicitly request the search (ignoring any method defined for the object in the current package) by using the "pseudoclass" SUPER and saying $a->SUPER::meth(arguments...).

The result is essentially multiple inheritance! If you start your class with the words

package MyClass;
@ISA = ('Shape', 'Storable');
then objects in MyClass will behave like objects of types Shape and Storable (in that order), except when overridden by definitions in MyClass. This being Perl, it's still up to MyClass' constructor "new" to arrange for Shape-specific and Storable-specific initializations to take place!

Note that this only applies to methods, not to instance variables (which Perl doesn't really have). But if $a is a hash reference of class MyClass, and if Storable uses an "instance variable" ...->{_v}, then $a->{_v} really accesses that "instance variable". But woe betide you if Shape (or MyClass) have instance variables that share this name!


printable version
chaos

late binding ten commandments for c++ programmers is-a @
multiple inheritance progasm check valve Viggo Mortensen
Inheritance Object Oriented Programming bless universal
Dynamic binding ISA
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Just another sprinkling of indeterminacy
Mayan Calendar
Windows 1.x
How to tenderize an octopus
Perl
Michelangelo
Chinese Dynasties
augmented triad
Jonathan Sidney Phillips
Sal Mineo
Webster 1913 is a fake
Aspects of American society that may be new to you
Thailand
¡MULTIPLE ORGANISMS!
New Writeups
The Jacket
Words of Advice(idea)
keepinitreal
Why buy the cow when you can get the milk for free?(idea)
John_Fox
Good Intentions Gone Wrong(person)
Cuckowski
Slavonic Princess(poetry)
Heitah
Posthumous Oscar(thing)
ignis_glaciesque
University of South Florida(place)
ignis_glaciesque
Flogstaskriket(idea)
liveforever
Caesar's last breath(idea)
dagnyswaggart
she wants to believe(personal)
antigravpussy
he doesn't know, but her eyes widen too far(thing)
dagnyswaggart
Wild tides guard her secrets(poetry)
Lord Brawl
Caesar's last breath(poetry)
locke baron
Forgotten things in space(fiction)
sitaraika
Colours(idea)
etouffee
Wild tides guard her secrets(poetry)
E2 is a by-product of the existence of The Everything Development Company