Multiple Inheritance

Olifant olifant at gmail.com
Fri Sep 28 02:54:18 PDT 2007


Say you have two interfaces: Visible and Selectable.

You want that everything that inherits from Visible, has the following two functions:
SetVisible: sets it to visible or not
GetVisible: returns what you last set it to with SetVisible

You want that everything that inherits from Selectable, has the following two functions:
SetSelected: sets it to selected or not
GetSelected: returns what you last set it to with SetSelected

Some classes inherit only from Visible, others only from Selectable, others from both.

In C++, you can easily do this: put the implementations in the Visible and the Selectable interface.

How can this be done in D? I mean to avoid that everyone who inherits from one of them has to write his own implementation of GetVisible/SetVisible/GetSelected/SetSelected over and over again, after all it's always the same.

Is there some way to get such an effect with a language without multiple inheritance, maybe even without inheritance at all, but still with the ability to be able to make lists of Visible and of Selectable objects no matter what subtype they are?



More information about the Digitalmars-d mailing list