Your base class should not really have to guess all the future ways in which derived child classes can screw things up :) in the base class, implement the method you want:
This works to any depth of inheritance. One of the main benefits of OO is this type of inheritance where you can specialise a child class without having to recode the Parent and causing unanticipated issues elsewhere.package Parent; sub X { my $self = shift @_; print "called Parent::X()\n"; ... } # ------------------- # and in the Child class you specialise this package Child; use base qw(Parent) sub X { my $self = shift @_; $self->SUPER::X(@_); # Call Base class method # then do some extra stuff print "called Child::X()\n"; ... } # ------------------- # and further down the chain... package GrandChild; use base qw(Child) sub X { my $self = shift @_; $self->SUPER::X(@_); # Call up one level # then do some extra grandchild stuff print "called GrandChild::X()\n"; ... }
So in my opinion, _Private_X should be court marshalled. I usually find that $obj->can('method') is more suited for use in handling collections of different types of objects. If you are using it for an inheritance hierarchy trick, look again - its probably a mistake.
Regards,
Jeff
In reply to Re: overridden method - best way
by jaa
in thread overridden method - best way
by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |