Learning Perl Objects, References amp;amp; Modules [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learning Perl Objects, References amp;amp; Modules [Electronic resources] - نسخه متنی

Randal L. Schwartz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید














11.6 Multiple Inheritance


How does Perl wander through the
@ISA tree? The answer may be simple or complex. If
you don't have multiple inheritance (that is, if no
@ISA has more than one element), it is simple:
Perl simply goes from one @ISA to the next until
it finds the ultimate base class whose @ISA is
empty.

Multiple inheritance is more complex. It occurs when a
class's @ISA has more than one
element. For example, suppose someone had given an existing class,
called Racer, which has the basic abilities for
anything that can race, so that it's ready to be the
base class for a runner, a fast car, or a racing turtle. With that,
you can make the RaceHorse class as simply as
this, maybe:[2]

[2] If there is a conflict among the methods
of Horse and Racer, or if their
implementations aren't able to work together, the
situation can become much more difficult.


{
package RaceHorse;
our @ISA = qw{ Horse Racer };
}

Now a RaceHorse can do anything a
Horse can do, and anything a
Racer can do as well. When Perl searches for a
method that's not provided directly by
RaceHorse, it first searches through all the
capabilities of the Horse (including all its
parent classes, such as Animal). When the
Horse possibilities are exhausted, Perl turns to
see whether Racer (or one of its subclasses)
supplies the needed method. On the other hand, if you want Perl to
search Racer and its subclasses before searching
Horse, put them into @ISA in
that order (see Figure 11-1).


Figure 11-1. A class may not need to implement any methods of its own if it inherits everything it needs from its parent classes through multiple inheritance




/ 199