You are completely correct. As I say in the wiki page, mixins are a power tool, incorrect usage may lead to loss of limbs. (There is a similar concept, called traits, which is much more restrictive, and won't let you make this mistake -- but then again, they are found limiting by true hackers. :P)
Also as I say in the wiki page, and I hope what I said is true, your second example should fail to compile in the swf10 runtime. The Flex compiler should notice that you are calling a non-existent super method at compile time, and complain. The way traits solve this problem is that you are not allowed to call super methods at all. Basically, you would write methods for mydraw, mix1draw, mix2draw, basedraw, etc. and you would have to 'combine' those methods by hand. So, their solution is essentially to take the power tool away from you. We could probably do a little more checking in the compiler to prevent you from making this silly mistake. The compiler could surely at least verify that the superclass had a method of the correct name when it sees a super call. Sounds like a great improvement for Don to implement in his spare time... :) On 2011-01-24, at 18:43, [email protected] wrote: > Hi Tucker, > > I read your wiki page about mixins, http://wiki.openlaszlo.org/Mixins. I > wrote an application to verify that inheritance works as described (it does). > I defined a draw() member in a base class, two mixins, and a subclass (see > Example 1 below). When you run this it displays: > > baseclass.draw init > drawmixin2.draw init > drawmixin1.draw init > myclass.draw init > > My worry isn't that multiple mixin draw() methods are called, but rather the > opposite case. If this mixin is used in another example, you can wind up > calling a non-existent super class. See Example 2. This is the same as > Example 1 except that there is no base class. > > Is there a way the application can detect (at runtime) that there is no super > class? > > Thanks! > > Phil > > > EXAMPLE 1: > > <canvas debug="true"> > <class name="baseclass"> > <method name="draw" args="str"> > Debug.write("baseclass.draw", str); > </method> > </class> > > <mixin name="drawmixin1"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("drawmixin1.draw", str); > </method> > </mixin> > > <mixin name="drawmixin2"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("drawmixin2.draw", str); > </method> > </mixin> > > <class name="myclass" extends="baseclass" with="drawmixin1,drawmixin2"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("myclass.draw", str); > </method> > </class> > > <myclass name="c1"/> > > <handler name="oninit"> > c1.draw ("init"); > </handler> > > </canvas> > > > > EXAMPLE 2: > > <canvas debug="true"> > <mixin name="drawmixin1"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("drawmixin1.draw", str); > </method> > </mixin> > > <mixin name="drawmixin2"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("drawmixin2.draw", str); > </method> > </mixin> > > <class name="myclass" with="drawmixin1,drawmixin2"> > <method name="draw" args="str"> > super.draw(str); > Debug.write("myclass.draw", str); > </method> > </class> > > <myclass name="c1"/> > > <handler name="oninit"> > c1.draw ("init"); > </handler> > > </canvas>
