November 03, 2005Simulating enum inheritance?
How can you simulate enumeration inheritance so that later enums can automatically adopt all the constants of an earlier one? Application: I have basic messages that all GUI objects support and more specific messages to each type. Obviously a Button should messages specific to Lists (and vice versa) but they both understand things like redraw, move, destroy... I could fully qualify the enum reference every time I wanted to use something from the main class, but ... I'm in no hurry to develop carpal tunnel :) I could use mixins except they don't seem to work for enums (complains about items separated by commas rather than semicolons). Ideas? (I'm using enums for good reason) Thank you.
November 03, 2005Re: Simulating enum inheritance?
Posted in reply to Dwayne Robinson
> Ideas? (I'm using enums for good reason) Hmmm.. A static foreach comes to mind :-) No, don't look for it, it's not there. For the record, I remember an interesting point raised by Walter a few years ago: 'inherited' enums would behave differently from inherted classes in that an inherited class can be cast safely to the base, but an inherited enum (one with more values) cannot. In fact, the base enum can be cast to the inherited one.. I've always thought this was an interesting point. L.
Copyright © 1999-2016 by the D Language Foundation