Charles Monteiro is concerned about creating accessors that are only needed by class methods to set up the instance. Rather than using a special syntax for the class method, I would rather simply declare the instance method as being private. But every Smalltalker knows that methods aren't really private. Anyone can call any method in the system.
Although this may be theoretically true, in practice it is possible to make a method private. In VisualWorks, you just write the method like this:
property: anObject
self privateMethod.
property := anObject
Now, you just have to write privateMethod. You can do that like this:
privateMethod
(thisContext sender sender method mclass == self class
| (thisContext sender sender method mclass == self class class))
ifFalse: [PrivateMethodException raise]
This allows the method to be called by instance methods and class methods of the same class as the receiver.
Do you want protected methods that can only be called by class or instance methods of subclasses of the method? Try this:
protectedMethod
(self class isKindOf: thisContext sender sender method mclass
| (self class class isKindOf: thisContext sender sender method mclass))
ifFalse: [PrivateMethodException raise]
Private methods can be sent from one instance to another instance of the same class. How about a method that can only be called from other methods on the same instance? Try this:
selfPrivateMethod
thisContext sender sender receiver == self
ifFalse: [PrivateMethodException raise]
In fact, you could come up with methods that allow calls from a set of classes. You have much more flexibility than you would if private and protected were built into the language syntax.