Break OO privacy: Difference between revisions

→‎{{header|Common Lisp}}: Break off and extend paragraph on inheritance.
(→‎{{header|Common Lisp}}: Soothe exclamation outbreak.)
(→‎{{header|Common Lisp}}: Break off and extend paragraph on inheritance.)
Line 183:
Classes, generic functions and methods are objects. Their naming by symbols is secondary, in a way.
For instance, when we instantiate an object of class C in Lisp using <code>(make-instance 'c)</code>, we are actually invoking the specialization of the <code>make-instance</code> method to the <code>symbol</code> type. This method is a wrapper which invokes <code>(make-instance (find-class 'c))</code>, where <code>find-class</code> returns a class based on the symbol which names it. Ultimately, the instantiation method is being run on the class object, not the class name. The name is thus only loosely connected to the class. By contrast in other languages, the class name is a big deal. It establishes the name of a scope, and perhaps of special functions such as constructors, and such.
 
IfIn Lisp, if a superclass and a derived class define a slot of the same name, there is simply no clash. The result is that the derived class just has one slatslot of that name, andwith canthe overridederived class having control over certain attributes of the slot, such as redefining a shared (class-wide) slot to be local (per instance) or vice optionsversa. [http://www.lispworks.com/documentation/lw50/CLHS/Body/04_cd.htm]
 
The concept of privacy in Lisp is located in the package system. An external symbol S in package P can be accessed using P:S. If S is internal then P:S results in error at read time. This is completely independent of context and orthogonal to the use of symbols to denote class slots (instance variables), methods, functions, class names themselves, global variables, et cetera. Even if the private symbol appears in a literal piece of data like a quoted list, it is an error to refer to it: <code>(1 2 3 P:S)</code>. The internal symbol S in package P can be accessed using <code>P::S</code>. This is easy to do because programmers are assumed to be responsible grownups who can be trusted to know what they are donig. Also, note that this privacy is a property of the relationship between a symbol and a package. A symbol can be present in more than one package, such that it can be internal in some of them, and external in others.
Anonymous user