good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: inheritance: constructorsby dws (Chancellor) |
on Jun 24, 2002 at 22:26 UTC ( [id://176969]=note: print w/replies, xml ) | Need Help?? |
Inheritance in Perl is indeed clunkier to set up than in other languages. Is it worth it? That depends on what you're doing.
On to the particulars of your example:
A cleaner way is to separate "initialization" from creation. This cleans things up, at the expense, arguably, of more "clunk". Then we have to add a bit more clunk to deal with print $w->{english}; which commits the great OO sin of assuming private details of an object. The official way out of this is to add an "accessor" method to your base class.
In Section
Seekers of Perl Wisdom
|
|