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.
Index: doc/next-tutorial/next-tutorial.html =================================================================== diff -u -ra54313f558be3d0e7c909fa76cdee874f1880ef3 -r26480a59b14cf250904da0cdc7d895f21b0ed5fd --- doc/next-tutorial/next-tutorial.html (.../next-tutorial.html) (revision a54313f558be3d0e7c909fa76cdee874f1880ef3) +++ doc/next-tutorial/next-tutorial.html (.../next-tutorial.html) (revision 26480a59b14cf250904da0cdc7d895f21b0ed5fd) @@ -1623,7 +1623,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.
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").
All kind of method protections are applicable for all kind of methods, either scripted or C-implemented.
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.
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.
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + | # +# 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).
In the following example method, foo is an instance method defined on class C.