Multiple Inheritance of Classes
Yigal Chripun
yigal100 at gmail.com
Wed Aug 13 08:30:05 PDT 2008
superdan wrote:
> Yigal Chripun Wrote:
>
>> superdan wrote:
>>> Yigal Chripun Wrote:
>>>
>>>> About your first thought: can you compare your (C++ templates)
>>>> solution with D mixins? why would I choose that approach
>>>> instead of template mixins if it's only good for inheritance of
>>>> implementation? I think (and I'm sure you'll correct me if I'm
>>>> wrong) that mixins remove the need for that pattern entirely.
>>> how would the mixin solution look like?
>> I've attached a file with a sample solution with mixins. you can
>> put both mixins in the most derived class or put one inside the
>> other (as it is now)
>
> got it. the question was how does that compare to stacked templates.
> guess they've about the same power. tho i suggest u move mixin B_impl
> outta B_impl and into A_and_B. why force A_impl as a bundle deal for
> B_impl.
I put one mixin inside the other just to show a similar implementation
to the c++ approach you've shown, but I agree, both mixins should be in
A_and_B (As I mentioned in my previous post).
Also note that the interfaces are only needed if you want to subtype. in
case all you need is "implementation inheritance" (as in c++) the mixins
suffice.
About non fixed layout languages, and specifically about JavaScript:
JavaScript doesn't provide MI.
it is easy to implement of course but it is not built in the language.
the language is prototype-based and each object has _one_ prototype only
from which it is "derived". if you want MI in JavaScript (and I really
don't see a reason why one would want to do it) all you need to do is
add to the object's prototype an array of all the "parent" object
prototypes and a function to search that array.
More information about the Digitalmars-d
mailing list