Think about Loose Coupling | |
PerlMonks |
Re: How can I add private data/methods in parent class?by ihb (Deacon) |
on Jun 22, 2004 at 13:54 UTC ( [id://368722]=note: print w/replies, xml ) | Need Help?? |
I think the real question you should ask yourself is why you want them to be private. Is it so that no one will be able to call them? If that's the case, you usually do well with just documenting them to not be called. I've never felt the need to "by force" hinder anyone from calling any of my methods. However, if it's because you don't want anyone to accidently overload your methods you could simply not call your method like a method but rather as a function, which is what a private method call is in this context. I usually do _foo($self => @args); and then no subclass can overload my _foo by adding it's own _foo. If you know which code you want to call, then call that code directly. Note that this isn't done to force any subclass to not call _foo, but rather prevent any subclass from accidently overloading _foo with its own "private" method. This is particularily apparent for _init methods. ihb
In Section
Seekers of Perl Wisdom
|
|