Coming from doing a lot of java and C#, a lot of my classes' internal processing would be done with private methods. Is there a similar mechanism in smalltalk? I suspect I may be thinking about this all wrong :-) -- View this message in context: http://forum.world.st/Private-methods-tp3022981p3022981.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Private methods don't exist in Smalltalk. Every method is exposed as public, and anyone can call it, from anywhere. As you can select a protocol for your methods to arrange them under a name or category, you may use the "private" category. This indicates to the users that a method is private, and should not be called from outside the class. As oposite, every instance variable is protected, and it can be seen just from the class and its subclases. If you want to expose a variable, you need to create accessors. Hope this helps you. C Ya -- Alan Rodas Bonjour
There is a convention of naming private methods - instead of naming it just "methodName" you can use "myMethodName". I have seen this convention in some tutorials at squeak wiki but have not seen a system class in squeak or pharo which uses this. But I do in my programs. A different naming convention of private/protected methods is quite common in other programming or scripting languages like Perl, Python, PHP ... -- View this message in context: http://forum.world.st/Private-methods-tp3022981p3023395.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Hi Am 2010-11-02 um 10:24 schrieb eMko:
There is a convention of naming private methods - instead of naming it just "methodName" you can use "myMethodName".
I have seen this convention in some tutorials at squeak wiki but have not seen a system class in squeak or pharo which uses this. But I do in my programs. A different naming convention of private/protected methods is quite common in other programming or scripting languages like Perl, Python, PHP ...
Incidentally, if you name your method "pvtMethodName" it is expected that this message is only sent to self. So if you have a class "--" Object subclass: #Foobar instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'TMP' "--" with Foobar>>pvtTest Transcript show: 'Foobar'. and then do | a | a := Foobar new. a pvtTest. you'll end up with the Compiler telling you that âPrivate messages may only be sent to selfâ. However, according to Smalltalk conventions, you should use these âprivateâ methods scarcely. In fact, it is easy to circumvent this check: | a | a := Foobar new. a perform: #pvtTest a Foobar works easily, so don't rely on the privateness. However, whatever one sends to your object is up to her/him and she/he is responsible for the outcome ;) HTH So Long, -Tobias
participants (4)
-
Alan Rodas -
eMko -
Jeff Gray -
Tobias Pape