in reply to Re^2: Object Constructors - Advice of experienced OO Perl Monks
in thread Object Constructors - Advice of experienced OO Perl Monks
MI == multiple inheritance
What he is basically saying is instead of having something like:
sub new { my ($class, %args) = @_; my $self = bless( {}, $class ); foreach my $k ( keys(%args) ) { $self{$k} = $args{$k}; } return( $self ); }
do something like:
sub new { my ($class, %args) = @_; my $self = bless( {}, $class ); $self->init(%args); return( $self ); } sub init { my ($self, %args) = @_; foreach my $k ( keys(%args) ) { $$self{$k} = $args{$k}; } # anyother initialization here }
This makes a clean separation between the construction and the initialization with no real downside.
Frank Wiles <frank@wiles.org>
http://www.wiles.org
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Object Constructors - Advice of experienced OO Perl Monks
by Perl Mouse (Chaplain) on Oct 06, 2005 at 15:51 UTC | |
by izut (Chaplain) on Oct 06, 2005 at 16:24 UTC | |
by izut (Chaplain) on Oct 06, 2005 at 16:36 UTC | |
by Perl Mouse (Chaplain) on Oct 06, 2005 at 16:46 UTC | |
by Perl Mouse (Chaplain) on Oct 06, 2005 at 16:28 UTC |