|laziness, impatience, and hubris|
use fields, underscores and subclassesby MattLG (Sexton)
|on Nov 23, 2008 at 00:06 UTC||Need Help??|
MattLG has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to use the fields module (on 5.8) in my OO code but it seems that fields wants to make all my "protected" fields private because they start with underscores.
This feature seems to be well documented, but not the reasoning or the "correct" way to do protected variables.
If I just remove the underscores, that now tells the users that these variables are free to use as you please, whereas they should really understand that if they choose to use them, they take responsibility for any unexpected behaviour.
If perl doesn't have a concept of protected variables, then class inheritance becomes pointless, surely.
So, how do I create variables that are visible to subclasses but tell the user not to use them if they know what's good for them?
It seems to me that making everything public and using underscores makes a hell of a lot more sense than providing private functionality but not protected.