Note that this variant doesn't hardcode baseclass name.my ($class, $whatever) = @_; my %params = (); # new params to use instead of parent's params my $self = $class->SUPER::new(%params); # create a new parent bless($self, $class); # rebless into the current package
BTW I strongly advice against using $this in Perl code. Most Perl programmers are too get used to $self. I recall than in the company where I worked until recenly we have one programmer (who was Java fan but liked Perl too) who used $this in his code. It was big PITA for everybody who had to edit that code. Fingers just type $self and only later you release (when you see Global symbol "$self" requires explicit package name) that it should be $this. After several such accidents we just told him that $this is forbidden :)
Anyway there is nothing wrong in using same constructor in all classes as long as it deffers object initialization to some methods which are overriden in subclasses. Actually it is very common practice and not only in Perl.
--
Ilya Martynov
(http://martynov.org/)
In reply to Re: super(params)
by IlyaM
in thread OO - problem with inheritance
by uwevoelker
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |