Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to How can I add private data/methods in parent class?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://368722]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found