Multiple Inheritance of Classes

superdan super at dan.org
Tue Aug 12 16:22:50 PDT 2008


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?

> In another post of yours you referred to adding function bodies to
> interfaces. Do you have any ideas on how to implement this efficiently?

each interface defines a vtable layout. it does not define what the table contains. a class implementing an interface will fill that vtable with its own functions. if a class forgets to fill all slots there's an error because there's nothing to fill that slot with. with me so far?

now if an interface defines function bodies, that simply means there are defaults for some of those entries. that's all. if the derived class doesn't fill them they are filled and the compiler calls it a day. (walt please confirm.)

now i know everybody and their fave hooker has a pet feature to add to d, but i'd really like that shit in d2. it would raise interface powers to a whole new level. why? because you can define an interface that defines high-level functions that callers can use yet requires the implementers to implement the low-level primitives. i think i saw this shit in herb sutter. he calls it non-virtual idiom or some'n'.

that shit is essential for contracts, too. contracts in d are fucked up. it's a cryin' shame. contracts should be on interfaces so they enforce shit on their implementors. as they should. right now only implementors can enforce shit on their own ass. how's that helpful i don't see.

interface Stack!(T)
{
    bool empty();
    T push() out { enforce(!empty); }
    T pop() in { enforce(!empty); }
    T top() in { enforce(!empty); }
}

now the stack writer not only wishes the implementer does some sensible shit. he also makes sure shit is respected. and if you think of it for a minute you'll see how this kind of requires implementation of functions in interfaces.

> last question: can you explain what do you mean by non fixed layout
> languages that have MI?

clos, python, perl, curl. even javascript. they have non-fixed layout. with hashes mapping names to values and shit. they would have to go out of their way to disallow mi. so they just allow it because "it's not evil". it just costs.



More information about the Digitalmars-d mailing list