inheritance

nkuipers nkuipers at uvic.ca
Wed Feb 19 17:51:18 CST 2003


Hello,

I've been playing around with inheritance and I've got a question.  Let's say 
the parent class is called BIO::Basic and the child class is called 
BIO::Annotate, and each class is in a separate file.

Parent constructor is as follows:

sub new {
        my $caller = shift;
        my $type = ref($caller) || $caller;
        my $self = { id       => 'no value',
		     desc     => 'no value',
                     seq      => 'no value',
		     alphabet => 'no value',
		     profile  => {},
                     @_ };
.
.
.
bless $self, $type;
}

Child constructor is as follows:

sub new {
	my $type = shift;
	my $self = {};
	$self->{bogus_key} = BIO::Basic->new(@_);
	bless $self, $type;
}

If I just call $self = BIO::Basic->new(@_), then Annotate objects cannot use 
Basic methods.  Addition of the {super} key in Annotate's self allows access 
to Basic methods in the driver script, as in:

$annotate_object->{bogus_key}->parent_method();

Am I missing something here?  Isn't there a simpler way?  I guess I'm used to 
the inheritance of java.  I got the above approach from

http://www.perldoc.com/perl5.6/pod/perlbot.html

Thanks,

Nathanael




More information about the Victoria-pm mailing list