in reply to Supra Class for Inheritance?
You get that behaviour by default.
{ package Parent; sub new { my ($class) = @_; return bless({}, $class); } sub finalise { my ($self) = @_; $self->finalise_body(); } sub finalise_body { my ($self) = @_; print(__PACKAGE__, "\n"); } } { package ChildWith; our @ISA = 'Parent'; sub finalise_body { my ($self) = @_; print(__PACKAGE__, "\n"); } } { package ChildWithout; our @ISA = 'Parent'; } { ChildWith ->new->finalise(); # ChildWith ChildWithout->new->finalise(); # Parent }
In C++ term, methods of this type are called virtual methods.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Supra Class for Inheritance?
by tbutler (Initiate) on Aug 21, 2010 at 02:51 UTC |