D mixins

Lutger lutger.blijdestijn at gmail.com
Thu Jan 4 14:35:52 PST 2007


Chris Nicholson-Sauls wrote:
> janderson wrote:
>> Lutger wrote:
>>> janderson wrote:
>>>> I'm trying to explain to a friend on msn what mixins are.  Can you
>>>> provide some good examples, that would be difficult otherwise?
>>>>
>>>> -Joel
>>>
>>> What about implementing multiple inheritance in a language that does 
>>> not have multiple inheritance? (interface + mixin as default 
>>> implementation)
>>
>> Thanks for your reply.
>>
>> Well coming from C++ this would not make much sense.  Where would you 
>> use them in C++?  Where would you use them in D?  Are there any good D 
>> examples that show the power of mixins in a simple way that would be 
>> more ugly another way?
>>
>> Cheers.
>> -Joel

Yes indeed, this is not a good example vis-a-vis C++.

Private inheritance in C++ is sometimes called mixin. So here, 
inheritance is used (but more restrictive) to emulate mixin's.

I find the seperation between (single) inheritance, interface and raw 
code injection better conceptually in D. In C++ it's all lumped together 
in inheritance, which makes it harder to distinguish intent.

There surely are good examples, I haven't used mixins myself in such a 
way that you are asking for.

Of course it is a unconvincing argument to make, but I would rather ask 
the question if there are any good examples where MI a la C++ is cleaner 
than interface and / or mixins because MI is so ugly it's on par with 
preproccesor macros and template template arguments.

> I think the Signals/Slots implementation in Phobos is a good example.
> 
> -- Chris Nicholson-Sauls

I think you can achieve this as easy with multiple inheritance in C++?



More information about the Digitalmars-d mailing list