Index: doc/next-tutorial/next-tutorial.txt =================================================================== diff -u -ra54313f558be3d0e7c909fa76cdee874f1880ef3 -r26480a59b14cf250904da0cdc7d895f21b0ed5fd --- doc/next-tutorial/next-tutorial.txt (.../next-tutorial.txt) (revision a54313f558be3d0e7c909fa76cdee874f1880ef3) +++ doc/next-tutorial/next-tutorial.txt (.../next-tutorial.txt) (revision 26480a59b14cf250904da0cdc7d895f21b0ed5fd) @@ -674,7 +674,7 @@ ========================================= A *property* is a definition of an attribute (an instance variable) -with accessors. The property definition might as well carry +with accessor methods. A property definition might carry value-constraints and a default value. ========================================= @@ -748,6 +748,7 @@ accessor method +name+ to obtain the value of the instance variable +name+ of object +s1+. + ==== Instance Variables without Accessors To define instances variables with default values without accessors @@ -1039,15 +1040,15 @@ be called. The Next Scripting Framework supports as well redefinition protection for methods. -NX distinguished between _public_, _protected_ and _private_ methods, -where the default call-protection is "protected". +NX distinguishes between +public+, +protected+ and +private+ methods, +where the default call-protection is +protected+. =========================================== A *public* method can be called from every context. A *protected* method can only be invoked from the same object. A *private* method can only be invoked from methods defined on the same entity (defined on the same class or on the same object) via the invocation -with the local flag (i.e. "+: -local+"). +with the local flag (i.e. "+: -local foo+"). =========================================== All kind of method protections are applicable for all kind of methods, @@ -1132,12 +1133,62 @@ all other purposes, the private methods are "invisible" in all situations, e.g., when mixins are used, or within the +next+-path, etc. -By using the +local+ flag for the invocation it is possible to call +By using the +-local+ flag at the call site it is possible to invoce only the local definition of the method. If we would call the method -as usual, the resolution order would be the same as usual, starting -with filters, mixins, per-object methods and the full intrinsic class -hierarchy. +without this flag, the resolution order would be the standard +resolution order, starting with filters, mixins, per-object methods +and the full intrinsic class hierarchy. +NX supports the modifier +private+ for methods and properties. In all +cases +private+ is an instrument to avoid unanticipated interactions +and means actually "accessible for methods defined on the same entity +(object or class)". The main usage for +private+ is to improve +locality of the code e.g. for compositional operations. + +In order to improve locality for properties, a private property +defines therfore internally a variable with a different name to avoid +unintended interactions. The variable should be accessed via the +private accessor, which can be invoved with the +-local+ flag. In the +following example class +D+ introduces a private property with the +same name as a property in the superclass. + +[[xmp-private-properties]] +.Listing {counter:figure-number}: Private Properties +{set:xmp-private-properties:Listing {figure-number}} +[source,tcl,numbers] +-------------------------------------------------- +# +# Define a class C with a (public) property "x" +# +nx::Class create C { + :property {x c} +} + +# +# Define a subclass D with a private property "x" +# and a method bar, which is capable of accessing +# the private property. +# +nx::Class create D -superclass C { + :private property {x d} + :public method bar {p} {return [: -local $p]} +} + +# +# The private and public (or protected) properties +# define internally separate variable that do not +# conflict. +# +D create d1 +puts [d1 x] ;# prints "c" +puts [d1 bar x] ;# prints "d" +-------------------------------------------------- + +Without the +private+ definition of the property, the definition of +property +x+ in class +D+ would shadow the +definition of the property in the superclass +C+ for its instances +(+d1 x+ or +set :x+ would return +d+ instead of +c+). + === Applicability of Methods As defined above, a method is a subroutine defined on an object or