This is not necessarily the current version of this TIP.
|Title:||Improved Variable Handling in the Core Object System|
|Version:||$Revision: 1.1 $|
|Author:||Donal K. Fellows <dkf at users dot sf dot net>|
|Created:||Friday, 13 June 2008|
This TIP specifies new configuration commands that allow variables to be used in methods of the core object system without explicit declaration in each method.
During the discussions leading up to the vote on TIP #257, it became apparent that being able to access at least some variables of an object without explicit declaration in each method was desirable. Doing this would make working with the core object system much easier in many common cases, and would also allow for potentially more efficient implementation.
However, there is a balance to be drawn. If every variable of the object was made available in the method by default (the simplest case) there would frequently be problems with interactions between the formal arguments of a superclass's methods and the instance variables of a subclass! That would be highly undesirable, as it completely breaks the principle of isolation of class implementations.
There are two ways of dealing with this issue.
Make the variables understood by a particular class be distinct from those understood by subclasses of the class.
Only bring those variables into scope that are actually declared by a particular class.
Studying the first alternative, there are two ways to actually achieve this: not putting the variables in a namespace but actually using a separate structure (poor, because then we would use the ability to easily use the variable with many of Tcl's general variable facilities), or modifying the namespace-visible name of each variable to include some unique string coupled to the class declaring it. Though I think that the second option is better than the first (actual implementations would be able to use the oo::object class's variable and varname methods to hide many of the details where they are currently exposed at all) I still do not particularly like it since it would mean that the cases wher