Index: doc/example-scripts/rosetta-delegates.html =================================================================== diff -u -r93bb0947d582f274afb1cdbc885909d55e100b36 -r24cb8f4bffd49c9375c1c64aa0610933b62511bb --- doc/example-scripts/rosetta-delegates.html (.../rosetta-delegates.html) (revision 93bb0947d582f274afb1cdbc885909d55e100b36) +++ doc/example-scripts/rosetta-delegates.html (.../rosetta-delegates.html) (revision 24cb8f4bffd49c9375c1c64aa0610933b62511bb) @@ -3,7 +3,7 @@ - + Listing of doc/example-scripts/rosetta-delegates.tcl +
package req nx
+
+nx::Class create Delegator {
+
+  # The class Delegator has a property named "delegatee" which is an
+  # object:
+
+  :property delegatee:object
+
+  # The method "operation" decides, whether it deletates the action to
+  # another object, or it performs the action itself.
+
+  :public method operation {} {
+    if {[info exists :delegatee]} {
+      ${:delegatee} operation
+    } else {
+      return "default implementatiton"
+    }
+  }
+}
+
+nx::Class create Delegatee {
+
+  # The class "Delgatee" might receice invocations from the class
+  # "Delegator"
+
+  :public method operation {} {
+    return "delegatee implementatiton"
+  }
+}

Demonstrating the behavior in a shell:

Create a Delegator, which has no delegatee defined. Therefore delegator performs the action by itself, the default implementation.

-
+
+
% set a [Delegator new]
+% $a operation
+default implementatiton

Now, we set the delegatee; therefore, the delegatee will perform the action.

-
+
+
% $a configure -delegatee [Delegatee new]
+% $a operation
+delegatee implementatiton