Index: doc/example-scripts/ruby-mixins.html =================================================================== diff -u -r4d11e2bfb1180867d9b5b6764ac1124d081b7ef1 -r0f57269d982e98ad81b82a12a5ab5b936784813f --- doc/example-scripts/ruby-mixins.html (.../ruby-mixins.html) (revision 4d11e2bfb1180867d9b5b6764ac1124d081b7ef1) +++ doc/example-scripts/ruby-mixins.html (.../ruby-mixins.html) (revision 0f57269d982e98ad81b82a12a5ab5b936784813f) @@ -734,25 +734,29 @@

Listing of doc/example-scripts/ruby-mixins.tcl

-
+
+

Design study to show the differences between decorator mixin classes and Ruby’s mixin modules

-

Design study to show differences between NX/XOTcl style mixin -classes and Ruby’s mixin modules. The example shows that the -dynamic class structure of NX (and XOTcl) is able to support -Ruby-style mixins (called modules) and decorator style mixins -(named after the design pattern Decorator) at the same time.

+

This example shows that the dynamic class structure of NX (and +XOTcl) is able to support Ruby style mixins (called modules) and +decorator style mixins (named after the design pattern Decorator) +in the same script.

One important difference between mixin classes in NX and Ruby’s mixins is the precedence order. While in NX, mixins are decorators (the mixins have higher precedence than the intrinsic classes, therefore a mixin class can overload the methods of the current -class), the mixins of Ruby have a lower precedence (they extend the -base behavior; although Ruby’s modules are not full classes, they -are folded into the intrinsic class hierarchy).

-

We define the method module, which behaves somewhat similar to -Ruby’s module command and adds the provided class to the -precedence order after the current class. The easiest way to achieve -this is via multiple inheritance (i.e. via the superclass -relationship).

+class and its subclasses), the mixins of Ruby have a lower +precedence (they extend the base behavior; although Ruby’s modules +are not full classes, they are folded into the intrinsic class +hierarchy). Therefore, a Ruby style mixin can be refined by the +class, into which it is mixed in (or by a subclass). Decorator style +mixins modify the behavior of a full intrinsic class tree, while +Ruby style mixins are compositional units for a single class.

+

To show the differences, we define the method module, which +behaves somewhat similar to Ruby’s module command. This method +adds the provided class to the precedence order after the current +class. The easiest way to achieve this is via multiple inheritance +(i.e. via the superclass relationship).