inheritance
Peter Scott
peter at PSDT.com
Thu Feb 20 20:42:49 CST 2003
At 06:17 PM 2/20/03 -0800, Darren Duncan wrote:
>On Wed, 19 Feb 2003, nkuipers wrote:
> > Child constructor is as follows:
> >
> > sub new {
> > my $type = shift;
> > my $self = {};
> > $self->{bogus_key} = BIO::Basic->new(@_);
> > bless $self, $type;
> > }
>
>Your child constructor is incorrect, and in this case, unnecessary.
Correct, unless he wants to do something in the constructor before
releasing the object into the wild. I should have said so before.
>The only reason to make your own new() is if you need to
>override or supplement functionality in the parent's new(). In the latter
>case, your child class' new() should look like this:
>
>sub new {
> my $self = SUPER::new(@_); # puts blessed hash in $self
Hmm, and here all the time I've been doing
my $class = shift;
my $self = $class->SUPER::new(@_);
Are you sure that with your approach it will go up the inheritance tree
if it doesn't find new() in the first superclass? I thought you needed
a -> method call for that.
> # put other special functionality here
> return($self);
>}
>
>Note that "SUPER" is a special Perl keyword that refers to the parent
>class. That said (and I don't really like this), when you have multiple
>inheritence, SUPER won't work
Well, it might :-) All depends which class it finds first.
>and you have to say instead
>"Bio::Basic::new(@_)".
Assuming that's the parent you want to inherit the constructor. If you
want some hybrid of the multiple parents' constructors you have to
figure it out the hard way, right?
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
More information about the Victoria-pm
mailing list