in reply to Re^2: Extending objects
in thread Extending objects
Question: Why are you using a separate init method outside of new? Any advantages to that?Because that makes multiple inheritance much easier. Assume ones Foo and Bar packages are:
Then you don't have a method that given a reference populates it. Both new methods return their own structure. Which means the bottom class needs to create two objects (by calling new in both parent classes), and then break encapsulation by tearing the two objects apart and constructing a new one.#### Foo.pm #### package Foo; sub new { my $self = bless {}, shift; my %args = @_; $self->{name} = $args{name}; $self; } sub name {$_[0]{name}} 1; #### Bar.pm #### package Bar; sub new { my $self = bless {}, shift; my %args = @_; $self->{age} = $args{age}; $self; } sub age {$_[0]{age}} 1;
|
|---|