Multiple subtyping with alias this and nested classes

Yigal Chripun yigal100 at gmail.com
Sat Oct 3 15:10:30 PDT 2009


On 03/10/2009 20:19, Max Samukha wrote:
> On Sat, 3 Oct 2009 14:11:37 -0300, Leandro Lucarella
> <llucax at gmail.com>  wrote:
>
>>
>> Ok, then, I just find it ugly and unnecessary since you can do the same
>> with interfaces+mixins.
>
> Actually, you can't. Consider:
>
> interface IBlipper
> {
>     void blip();
>     void nameCollision();
> }
> template Blipper()
> {
>     void blip() {}
>     void nameCollision() {}
> }
>
> interface IFlipper
> {
>     void flip();
>      void nameCollision();
> }
> template Flipper()
> {
>     void flip() {}
>     void nameCollision() {}
> }
>
> class FlippingBlipper : IBlipper, IFilpper
> {
>     mixin Flipper;
>     mixin Blipper;
> }
>
> The above sucks because we can't specify which nameCollision gets
> implemented by which mixin. In current D, nameCollision of both
> interfaces is implemented by Flipper.
>
> We would probably be able to overcome the limitation if and when
> explicit interface instantiation is implemented:
>
> template Blipper()
> {
>     void IBlipper.blip() {}
>     void IBlipper.nameCollision() {}
> }
>
> template Flipper()
> {
>     void IFlipper.flip() {}
>     void IFlipper.nameCollision() {}
> }
>
> Until then, mixin + interface just doesn't work.
>
>> It's just a matter of personal preferences (as
>> I said in my first mail), there is no point on arguing about it. =)

interfaces implement virtual MI, so FlippingBlipper must implement one 
nameCollision which is shared by both interfaces. however you can give 
names to mixins so that you could choose which implementation to use for 
that and also have both implementations.

class FlippingBlipper : IBlipper, IFilpper
{
     mixin Flipper F;
     mixin Blipper B;
     alias F.nameCollision nameCollision;
}

I wonder if the following would work:

class FlippingBlipper : IBlipper, IFilpper
{
     mixin Flipper IFilpper;
     mixin Blipper IBlipper;
}






More information about the Digitalmars-d mailing list