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).
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).