Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How can I make one class extend another one?

by Anonymous Monk
on Apr 20, 2000 at 20:27 UTC ( [id://8181]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I make one class extend another one?

Originally posted as a Categorized Question.

  • Comment on How can I make one class extend another one?

Replies are listed 'Best First'.
Re: How can I make one class extend another one?
by chromatic (Archbishop) on Apr 20, 2000 at 20:40 UTC
    Inheritance is very easy in Perl. Assuming we have a class PerlMonk, we could create a new class called vroom that extends the first:
    package vroom; @ISA = qw ( PerlMonk );
    From then on, for any method called on an instance of vroom that isn't defined immediately in the class, Perl will search the classes named in @vroom::ISA for those methods.

    That is, PerlMonk::dispense_wisdom() is available via $vroom->dispense_wisdom() even if there is no vroom::dispense_wisdom().

    Note that the @ISA array can contain lots of parent classes. Note also that they are searched left-to-right, depth first.

Re: How can I make one class extend another one?
by brother ab (Scribe) on Sep 19, 2000 at 09:20 UTC
    package Child; use base qw(Mother Father);

    base pragma not only includes extended classes in @INC, but 'require's them.

    Additionally, it is integrated with fields pragma (if you like strict data members protection)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found