atom feed19 messages in Mixin inheritance
FromSent OnAttachments
Brian GoetzMar 13, 2009 11:50 am 
Michael AzziMar 13, 2009 12:43 pm 
Brian GoetzMar 13, 2009 1:20 pm 
Michael AzziMar 13, 2009 1:42 pm 
Weiqi GaoMar 14, 2009 6:24 am 
Kim TopleyMar 14, 2009 7:40 am 
Robert FieldMar 15, 2009 12:53 pm 
Brian GoetzMar 16, 2009 11:18 am 
Brian GoetzMar 16, 2009 11:19 am 
Kim TopleyMar 16, 2009 12:21 pm 
Weiqi GaoMar 16, 2009 7:37 pm 
Brian GoetzMar 18, 2009 11:32 am 
Michael AzziMar 18, 2009 11:56 am 
Weiqi GaoMar 18, 2009 7:09 pm 
Brian GoetzMar 20, 2009 9:11 pm 
Brian GoetzMar 20, 2009 9:12 pm 
Brian GoetzMar 20, 2009 9:18 pm 
Weiqi GaoMay 3, 2009 7:31 pm 
Brian GoetzMay 3, 2009 7:52 pm 
Subject:Re: Mixin inheritance
From:Weiqi Gao (
Date:Mar 16, 2009 7:37:43 pm

Thanks Brian,

It all make sense.

It seems that even though a simple reference to count while inside the body of FootballVideo refers to Football's count, I can get at Video's count through the expression

(this as Video).count

and its value is independent of the simple reference of count, which is equal to

(this as Football).count

Brian Goetz wrote:

There is only one count variable.

Mixing is *not* multiple inheritance; it doesn't inherit a count from both Football and Video. Instead, what both Football and Video say is "The mixee class must have an int variable called count; if one does not exist, add one at mix time." Mixin fields are mixed in in the order the mixins are specified, so what happens is:

- FootballVideo wants to mixin Football - It doesn't have a 'count' var, so it gets one - Then it wants to mix in Video - It already has a count field, so nothing else happens.

In your example, there is a real conflict over "count". The mixin mechanism does not attempt to resolve that.

The play() method can be disambiguated by calling or

How will the accidental variable name conflicts in unrelated mixin classes be handled? In the following example:

public mixin class Football { public var count:Integer = 0; public function play() { println("Football playing"); count++; } }

public mixin class Video { public var count:Integer = 0; public function play() { println("Video playing"); count++; } }

public class FootballVideo extends Football, Video { public override function play() { println("FootballVideo playing");;; } }

there doesn't seem a way to get at the count variable from either Football or Video.