Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: inheritance turns back and bites

by borisz (Canon)
on Mar 01, 2004 at 13:28 UTC ( [id://332887]=note: print w/replies, xml ) Need Help??


in reply to inheritance turns back and bites

you expect that increment call SomeData::add, but it calls MyNumber::add. Because it is a MyNumber object. If you do not want that, write in package SomeData
sub increment { my $self = shift; $self->SomeData::add(number => 1); }
Boris

Replies are listed 'Best First'.
Re: Re: inheritance turns back and bites
by esskar (Deacon) on Mar 01, 2004 at 13:46 UTC
    Always use SUPER instead of the parent-class-name; so in the case of changeing the parent-class, you won't have to replace all the "SomeData::" stuff to the new parent-class-name.
    SUPER is pretty super.
      But SUPER is wrong here, I like to use SomeData or build something with __PACKAGE__.
      Boris
        If your intent is to ensure that increment calls add in the same package, why not use:
        sub increment { my $self = shift; &add($self, number => 1); }
        Use subroutine calls when you want to create your own explicit binding, use -> notation when you desire runtime binding of the message.

        Of course, it would be my opinion that it is particularly bad form for a child class to re-implement a method in a manner that is not backward compatible - it's a violation of the contract as far as I'm concerned.

        --Toby Ovod-Everett

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found