⭐ in reply to How do I make a constructor?
I tend to use:
That way all subclasses can initialize themselves in a standard way with something along the lines of:sub new { my $class = shift; my $self = {}; if (bless( $self, $class)->init( @_ )) { return $self; } else { # throw some sort of error } } sub init { 1; }
and I'll know if something goes wrong...sub init { my $self = shift; if ($self->SUPER::init( @_ )) { ## do some sort of initialization ## or return false return 1; } else { return 0; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Answer: How do I make a constructor? (different responsibilities)
by Aristotle (Chancellor) on Apr 13, 2003 at 12:51 UTC |
In Section
Seekers of Perl Wisdom