So someone on the cb pointed me at the perldoc for base, which describes itself as "Establish an ISA relationship with base classes at compile time". I'm guessing that this means that when I write:
that what I'm saying is that were I to write a test script reading:package MyPackage::Module::ThisFeature; use base MyPackage::Module;
that my first test would pass, but my second and third one would fail. Is that right?use Test::More 'no_plan'; my $obj = MyPackage::Module::ThisFeature->new(); isa_ok($obj,'MyPackage::Module'); isa_ok($obj,'MyPackage::Module::ThisFeature'); isa_ok($obj,'MyPackage::Module::ThatFeature');
But what I actually got was:
So I guess my object belongs to both its own class, as well as its base class, but not to a sister class, then.perl 01-test.t ok 1 - The object isa MyPackage::Module ok 2 - The object isa MyPackage::Module::ThisFeature not ok 3 - The object isa MyPackage::Module::ThatFeature
I'm getting to a point where this conceptual stuff is starting to break down for me. I think I'll start another thread on SoPW to try to untangle the the real world issue I'm struggling with now.
In my brief example below, if I understand this correctly, the "use base MyPackage::Module;" line permits both the MyPackage::Module::ThisFeature and the MyPackage::Module::ThatFeature to "inherit" methods from the MyPackage::Module. So that a script which reads:
will instantiate an object belonging to the "MyPackage::Module" class, which can use any of its class methods, as well as methods made available in the MyPackage::Module::ThisFeature package, except that the base class' ->this_method() method will be over-ridden by the version provided in the MyPackage::Module::ThisFeature package. Do I have this right so far?#!/usr/bin/perl -wT use strict; use warnings; use MyPackage::Module::ThisFeature; use MyPackage::Module::ThatFeature; my $obj = MyPackage::Module::ThisFeature->new(); my $result = $obj->this_method(); . . .
Is there some way to access methods in MyPackage::Module::ThatFeature, short of fully qualifying them as: MyPackage::Module::ThatFeature->still_another_method()?
Am I lost on this yet?
-- Hugh
package MyPackage::Module; sub new { . . . bless $self, $class; } sub this_method { } sub that_method { } 1; package MyPackage::Module::ThisFeature; use base MyPackage::Module; sub this_method { } sub some_other_method { } 1; package MyPackage::Module::ThatFeature; use base MyPackage::Module; sub that_method { } sub still_another_method { } 1;
In reply to Seeking clarification on Inheritance Issues by hesco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |