Since I am not sure about the intended semantics of constructors in tcloo, let me rephrase the example in nx (
http://next-scripting.org):
nx::Class create B {
:method init {} {set :bvar "fromB";next}
:public method getBvar args {return ${:bvar}}
}
nx::Class create A {
:mixin B
:method init {} {set :avar "fromA"}
:public method getAvar args {return ${:avar}}
}
In nx, the constructor is a method named "init". When a mixin is used in class A, the methods of the mixin B can potentially shadow all methods of A. The reason for this is that a mixin in xotcl/tcloo/nx is used as a decorator rather than a Ruby-style "mixin module" (see for the differences
https://next-scripting.org/xowiki/file/docs/nx/examples/ruby-mixins.html?html-content=1).
With a decorator mixin, the methods mixed-in can redefine the full behavior. In other words, the mixin has a higher precedence than the intrinsic classes. By using "info precedence"
set a [A new]
puts [$a info precedence]
one can see that B put into the precedence order before A, therefore the constructor of B requires a "next". On the contrary, when B is defined as superclass of A, the precedence order lists A before B, so there is no need for a "next" just to initialize "avar", but one will face the same problem with "bvar".
With nx, there is as well the option to initialize variables without constructor to avoid such problems at all. In nx, the default values for instance variables can be defined in a declarative way, using internally the same mechanism as method parameter.
nx::Class create B {
:variable bvar fromB
:public method getBvar args {return ${:bvar}}
}
nx::Class create A {
:mixin B
:variable avar fromA
:public method getAvar args {return ${:avar}}
}
set a [A new]
puts [$a getAvar]
This avoids the need of using constructors for such cases at all and provides more symmetry for different class composition techniques. Hope, this brings some insights....
all the best
-gustaf neumann