Newbie Question: What is 'private'
L. M. Rappaport
rapp at lmr.com
Thu Feb 18 16:40:14 UTC 1999
On Thu, 18 Feb 1999 09:13:24 -0700, you wrote (with possible editing):
>In my readings of various books and manuscripts in my quest for
>Smalltalk Gurudom, I have read several different definitions of
>what 'private' methods are.
>Here is what I have found so far:
>1. Private methods are methods that are being worked on and are
> not yet ready for general use. They are private in the
> sense that they are to be used only by the developer who
> is working on them. When they are ready for prime time they
> will be moved to another catagory.
This is not the classical definition of "private". Whether or not a
method is ready for general use is of no consequence. The idea behind
"private" methods are that they are intended for use within the class
and not exposed outside the boundaries of that class. You might have
a method category called "unfinished" to deal with the above.
>2. Private methods are private to the class. (I don't reall understand
> this, but I have read it somewhere.)
This is the classical definition. If "private-ness" were enforced, in
Smalltalk (which it is not), it would mean that you could not call a
private method outside the class in which it resides.
>3. There is no such thing as a private method in Smalltalk; it is
> only a non-enforcable convention that some programmers have
This is true by virtue of the fact that all methods are exposed in
classical Smalltalk, unless they are constrained by some artificial
device (see the message regarding "pvt" in method names)
>So what is it to be? I don't really >care< what the definition of
>private is, but I would like to >know< what the definition is.
Hope the above helps. There are no private methods in Smalltalk, yet
the concept is worth considering: When you design a class, you have
some methods which constitute a published interface. These are the
ones which you expect the outside world to use. You may also have
some methods which you consider private. These are typically
implementation details which are subject to change without affecting
your public interface. You might keep them in a category marked
"private", but with the understanding that it is just a "gentlemen's
rapp at lmr.com
More information about the Squeak-dev