Hi 2teez,
I'm not really happy with your suggestion for a newcomer. Why?
1) Choroba presented a simple constructor (as strong as pure water to stay with your metaphor) where you can can overwrite the default values of name and tail independently in a way most people would expect working with constructors in Perl. The positional parameters to new you present is not very common IMHO. So, I think Corion's constructor is really simple enough.
2) In package main you then do a
print $cat->{'name'}, $/;
which means you circumvent encapsulation (yes, I know, for debugging purposes). You show that to a newcommer to whom should be taught the "right" thing.
3) The point above IMHO comes only from the fact that you define the method nameMe in the child class. Why haven't you defined it in the base class? Then you wouldn't have to break encapsulation in your example and you would have shown inheritance in a nice mini example.
Be sure, I wouldn't have written this comment when Amblikai wouldn't have been so "excited" about your example. Please consider my comment as a hopefully constructive criticism.
And yes, Tobyink's answer is a hard drink to newcomers, but worth studying.
Best regards
McA
|