in reply to overridden method - best way

I would have the method X() in the children as well, and call SUPER from there if you want to run the parent method.
package MyChild; sub X { my $self = shift; $self->SUPER::X; # do stuff particular to the child }

Replies are listed 'Best First'.
Re^2: overridden method - best way
by adrianh (Chancellor) on May 25, 2004 at 23:56 UTC
    I would have the method X() in the children as well, and call SUPER from there if you want to run the parent method.

    The problem with this (and jaa's response) is that it solves a different problem from the OP's :-)

    When you specialise a method through inheritance you can either replace it completely, or add behaviour before and after it runs.

    However with the OP's method:

    sub X {    my $self = shift @_;    ...    $self->_Private_X();    ... }

    the behaviour that we want to tweak occurs in the middle of X's execution. You can't get at that by specialising X in a subclass.

    You see this pattern quite a lot when you have the same skeleton behaviour with various different implementations. The OP is doing exactly the right thing in isolating this behaviour that changes in a separate method that can then be specialised in each subclass.

      so why not make _Private_X a dummy method in the base class, and implement it in the children. Or am i not getting this thread?
        so why not make _Private_X a dummy method in the base class, and implement it in the children

        Yup. That's the way to go. I thought you were proposing to sub-class X not _Private_X.