in reply to class inheritance and new(constructor)
An inheritable constructor should use the second form of bless() which allows blessing directly into a specified class. Notice in this example that the object will be a BAR not a FOO, even though the constructor is in class FOO.
There is IMO nothing to add :) Re-using constructors is generally a good idea, as it makes the code more maintainable.package FOO; sub new { my $type = shift; my $self = {}; bless $self, $type; } sub baz { print "in FOO::baz()\n"; } package BAR; @ISA = qw(FOO); sub baz { print "in BAR::baz()\n"; } package main; $a = BAR->new; $a->baz;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: class inheritance and new(constructor)
by nmerriweather (Friar) on Jul 16, 2006 at 19:57 UTC |