Hello Gustaf,
playing around with mixins, I came across the following behaviour:
package require nx
nx::Class create TestMixin { :public method test {} { puts "mixin" } }
nx::Object mixin TestMixin
nx::Class create TestClass { :public method test {} { puts "class" } }
set test [TestClass new] puts [$test info precedence]; # => ::TestMixin ::TestClass ::nx::Object $test test; # => mixin
Is that intended? I would have expected that the class hierarchy of ::TestClass instances would look like "::TestClass ::TestMixin ::nx::Object".
Kind regards, Arthur
Dear Artur,
the mixins respect the class hierarchies, but maybe in a different way than you expected. Mixin classes have a higher precedence than the intrinsic classes (the actual class structure implied by the "class" relation and the "superclass" relations of this class). The details of the mixin semantics and mixin composition is defined in detail in the following paper:
http://nm.wu-wien.ac.at/research/publications/b613.pdf
As a summary, the full precedence order of an object is POMs PCMs O C
where POMs: a sequence of per-object mixins (classes, implying their super-classes) PCMs: a sequence of per-class mixins (classes, implying their super-classes) O: the actual object, not shown in "info precedence" C: the class of the object (implying its super-classes)
Mixins are sometimes criticized for their "total composition ordering"; a more fine-grained control can be provided via traits, see for an introductory example in:
http://nm.wu-wien.ac.at/research/publications/b886.pdf
all the best -gustaf neumann
On 23.02.12 11:29, Arthur Schreiber wrote:
Hello Gustaf,
playing around with mixins, I came across the following behaviour:
package require nx
nx::Class create TestMixin { :public method test {} { puts "mixin" } }
nx::Object mixin TestMixin
nx::Class create TestClass { :public method test {} { puts "class" } }
set test [TestClass new] puts [$test info precedence]; # => ::TestMixin ::TestClass ::nx::Object $test test; # => mixin
Is that intended? I would have expected that the class hierarchy of ::TestClass instances would look like "::TestClass ::TestMixin ::nx::Object".
Kind regards, Arthur _______________________________________________ Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl