| |
1090 |
1090 |
assign statements in the constructor requires explicit constructor |
| |
1091 |
1091 |
calls, which are often error-prone. Certainly, when a user prefers to |
| |
1092 |
1092 |
assign initial values to instance variables via explicit assign |
| |
1093 |
1093 |
operations in constructors, this is as well possible in NX. |
| |
1094 |
1094 |
|
| |
1095 |
1095 |
NX uses the same mechanism to define class variables or object |
| |
1096 |
1096 |
variables. |
| |
1097 |
1097 |
|
| |
1098 |
1098 |
[options="header",cols="asciidoc,asciidoc",frame="none",valign="middle"] |
| |
1099 |
1099 |
|====================== |
| |
1100 |
1100 |
|XOTcl |Next Scripting Language |
| |
1101 |
1101 |
|
| |
1102 |
1102 |
|[source,tcl] |
| |
1103 |
1103 |
---------------- |
| |
1104 |
1104 |
# No syntactic support for creating |
| |
1105 |
1105 |
# class variables |
| |
1106 |
1106 |
---------------- |
| |
1107 |
1107 |
|[source,tcl] |
| |
1108 |
1108 |
---------------- |
| |
1109 |
1109 |
|
| |
1110 |
|
# Define a object variable "V" with value 100 and |
| |
|
1110 |
# Define an object variable "V" with value 100 and |
| |
1111 |
1111 |
# an instance variable "x". "V" is defined for the |
| |
1112 |
1112 |
# class object Foo, "x" is defined in the |
| |
1113 |
1113 |
# instances of the class. "object variable" works |
| |
1114 |
1114 |
# similar to "object method". |
| |
1115 |
1115 |
|
| |
1116 |
1116 |
Class create Foo { |
| |
1117 |
1117 |
:object variable V 100 |
| |
1118 |
1118 |
:variable x 1 |
| |
1119 |
1119 |
} |
| |
1120 |
1120 |
---------------- |
| |
1121 |
1121 |
|====================== |
| |
1122 |
1122 |
|
| |
1123 |
1123 |
In the next step, we define configurable instance variables which we |
| |
1124 |
1124 |
call _properties_ in NX. |
| |
1125 |
1125 |
|
| |
1126 |
1126 |
XOTcl uses the method +parameter+ is a shortcut for creating multiple |
| |
1127 |
1127 |
configurable variables with automatically created accessors (methods for |
| |
1128 |
1128 |
reading and writing of the variables). In NX, the preferred way to |
| |
1129 |
1129 |
create configurable variables is to use the method +property+. The |
| |
1130 |
1130 |
method +property+ in NX is similar to +variable+, but makes the |