# XOTcl provides no means for method hiding
Index: TODO =================================================================== diff -u -N -rac96e6ce975fe5864b64dee9d66bc701a31e113b -r89714df5a6af5799a4444805cf1f82b4b2b21af2 --- TODO (.../TODO) (revision ac96e6ce975fe5864b64dee9d66bc701a31e113b) +++ TODO (.../TODO) (revision 89714df5a6af5799a4444805cf1f82b4b2b21af2) @@ -3429,12 +3429,17 @@ - nsf.c: * added permissable value "private" to flag "-callprotection" for - "info lookup method" and "info methods". + "info lookup method" and "inbfo methods". * extended regression test +- doc: + * fixed naming of "attribute" in migration guide + * added "private" to migration guide + * some textual improvements in migration guide + TODO: - private: - * document private in migration guide tutorial + * document private in tutorial - nx: * maybe provide a replacement for -attributes, but without the magic variable. Index: doc/next-migration.html =================================================================== diff -u -N -raa41f220776456c37553c5daf8e0519d5b51f0b8 -r89714df5a6af5799a4444805cf1f82b4b2b21af2 --- doc/next-migration.html (.../next-migration.html) (revision aa41f220776456c37553c5daf8e0519d5b51f0b8) +++ doc/next-migration.html (.../next-migration.html) (revision 89714df5a6af5799a4444805cf1f82b4b2b21af2) @@ -824,9 +824,9 @@
NX provides means for method protection (method modifiers - public and protected). Therefore developers have to define - explicitly public interfaces in order to use methods from other - objects. + public, protected and private). Therefore developers have + to define explicitly public interfaces in order to use methods + from other objects.
Total
43
123
44
124
Methods for Objects
18
20
51
Methods for Classes
4
23
3
24
Info-methods for Objects
14
15
25
Info-methods for Classes
7
6
24
NX supports the three method modifiers class, public and -protected. All method modifiers can be written in front of every method -defining command. The method modifier class is used to denote -class-specific methods (see above). The concept of method -protection is new in NX.
NX supports four method modifiers class, public, protected and +private. All method modifiers can be written in front of every +method defining command. The method modifier class is used to denote +class-specific methods (see above). The concept of method protection +is new in NX.
@@ -1734,39 +1733,108 @@
# Method modifiers # # "class", -# "public", and +# "public", # "protected" # # are applicable for all kinds of method # defining methods: # -# method, forward, alias, attribute - -Class create C { +# method, forward, alias, property +# +# The modifier "private" is available for +# +# method, forward, alias +# +Class create C { :/method-definiton-method/ ... :public /method-definiton-method/ ... :protected /method-definiton-method/ ... + :private /method-definiton-method/ ... :class /method-definiton-method/ ... - :protected class /method-definiton-method/ ... :public class /method-definiton-method/ ... + :protected class /method-definiton-method/ ... + :private class /method-definiton-method/ ... } |
XOTcl does not provide method protection. In NX, all methods are -defined per default as protected. These defaults can be changed by the +defined per default as protected. This default can be changed by the application developer in various ways. The command ::nx::configure defaultMethodCallProtection true|false can be used to set the default call protection for scripted methods, forwarder and aliases, while ::nx::configure defaultPropertyCallProtection true|false can set the default protection for properties. The defaults can be overwritten also e.g. on a class level.
NX provides means for method hiding via the method modifier
+private. Hidden methods can be invoked only via +my -local
+which means: "call the specified method defined in the same
+class/object as the currently executing method".
XOTcl | +Next Scripting Language | +
---|---|
+
+ # XOTcl provides no means for method hiding |
+
+
+ # Hiding of methods via "private" +# +nx::Class create Base { + :private method baz {a b} { expr {$a + $b} } + :public method foo {a b} { my -local baz $a $b } +} + +nx::Class create Sub -superclass Base { + :public method bar {a b} { my -local baz $a $b } + :private method baz {a b} { expr {$a * $b} } + + :create s1 +} + +s1 foo 3 4 ;# returns 7 +s1 bar 3 4 ;# returns 12 +s1 baz 3 4 ;# unable to dispatch method 'baz' |
+
NX provides an explicit delete method for the deletion of methods -and attributes.
# Set instance variable of object obj to a # value via resolver -# (preferred way: define attribute on obj) +# (preferred way: define property on obj) /obj/ eval [list set /:varName/ ?value?] |
@@ -2318,38 +2386,55 @@
+
+ +# The method "variable" is similar in syntax +# to Tcl's "variable" command. During object +# creation, the definition are used for the +# initialization of the object. + +Class create Foo { + :variable x 1 + :variable y 2 +} + +# Create instance of the class Foo +Foo create f1 + +# Object f1 has instance variables +# x == 1 and y == 2 |
+
+
+
While XOTcl follows a procedural way to initialize variables via the +constructor init, NX follows a more declarative approach. Note, that +the variable definitions are inherited from superclasses, which is +straightforward in NX, while in XOTcl, the constructor has to call +explicitly the constructor of its superclasses.
It is certainly as well possible to use constructors in NX in the same +way as in XOTcl.
NX uses the same mechanism to define class variables or object +variables.
XOTcl | +Next Scripting Language | +
---|---|
+
+ # No syntactic support for creating +# class variables |
+
+
+ +# Define a class variable "V" with value 100 and +# an instance variable "x". "class variable" works +# similar to "class method". + +Class create Foo { + :class variable V 100 + :variable x 1 +} |
+
In the next step, we define properties, i.e. variables with accessors.
XOTcl uses the method parameter is a shortcut for creating multiple +properties. For every parameter definition, XOTcl creates as well a +slot object, keeping an extensible set of meta-data for every +parameter. Slot objects can be as well created in XOTcl directly via +the method slots. NX provides a similar method named properties.
XOTcl | +Next Scripting Language | +|
---|---|---|
+ # Object parameter specified as a list (short form) # "a" has no default, "b" has default "1" @@ -2384,7 +2609,8 @@ # Create instance of the class Foo Foo f1 -a 0 -# Object f1 has a == 0 and b == 1 |
+# Object f1 has instance variables
+# a == 0 and b == 1
- # Object parameter specified via slots
+ |
+
+# Use the setter to alter instance variable "b"
+f1 b 100
+
+# Use the accessor to output the value
+puts [f1 b]
- # Object parameter specified via attribute -# methods (supports method modifiers and -# scripted configuration) +# Object parameters specified via the method +# "property" (supports method modifiers and +# scripted configuration; see below) Class create Foo { :property a :property {b 1} } -# Create instance of the class Foo +# Create instance of the class Foo and +# provide a value for instance variable "a" Foo create f1 -a 0 -# Object f1 has a == 0 and b == 1 |
+# Object f1 has a == 0 and b == 1
+
+# Use the setter to alter instance variable "b"
+f1 b 100
+
+# Use the accessor to output the value
+puts [f1 b]
@@ -2526,17 +2771,17 @@
.nx-placeholder {color: #AF663F; font-weight: normal; font-style: italic;}
.nx-variable {color: #AF663F; font-weight: normal; font-style: normal;}
- # Define object parameter at the class -# and object level +# Define a class property and an object +# property Class create C { :property x :property {y 1} - :class attribute oa1 + :class property cp } Object create o { - :property oa2 + :property op } |
||
- /obj|cls/ info [inst](commands|procs|parametercmd) ?pattern? |
+