>>>>> "Brad" == Brad Carlson <[EMAIL PROTECTED]> writes:
Brad> Just to clarify, the only reason I don't need a new() method in the
Brad> subclass is because any class-specific logic is contained in the _init()
Brad> method for both parent and subclass. If there were no _init() method,
Brad> then both classes would have a new(), right?
Yes. You can either put your per-class initialization into ->new,
and use SUPER::new for parent classes, or have an _init, which your
most-parent-class must remember to call. The latter is a Smalltalk-ish
standard, where "Object class"[1] has something like:
new
^self basicNew initialize
and initialize[2] looks like
initialize
^self
Then every derived class that wants additional hooks does:
initialize
super initialize.
"my code here."
^self
In Perl terms, this would look like:
sub new {
my $class = shift;
my $self = bless [EMAIL PROTECTED], $class;
return $self->initialize; # and return this
}
sub initialize { # base definition
my $self = shift;
return $self;
}
sub initialize { # derived definition
my $self = shift;
$self->SUPER::initialize;
$self->{extra} = "thing";
return $self;
}
By the way, I really really recommend that people who are doing
serious OO get some Smalltalk experience. Smalltalk got a *lot*
of things right. Free implementations of Smalltalk for all platforms
are available at <www.squeak.org>, and there's a wealth of both free
and commercial publications about learning Smalltalk.
[1] Actually, it's in "Behavior class".
[2] Defined in ProtoObject, the base class for Object
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>