[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python enumerations



------ Original Message ------
> While thinking about the problem, it occured to me that that classes
> could also be used as enumerations - not class names, but the actual
> object representing a class, like this:
> 
That sounds smart and probably the best solution to Dan's initial problem, but
it doesn't sound like an enumeration - the core feature of an enum is that it
is a canonical set of options for a given context. Nothing about the approach
of having classes represent elements of an enum supports the idea that the
fruits you have defined represent all the valid fruits, and more importantly
there's no way good way to find or describe the list of all of them (i.e. the
"enum" isn't canonical and isn't given a context)

So it sounds like maybe an enum isn't what Dan really needed, but if someone
wanted to make the class approach more enum-like, they'd probably want to use
something like class inheritance (i.e. Peach derives from fruit, Apple derives
from fruit, anything that doesn't derive from fruit isn't a fruit and to find
all fruits you find all the subclasses of fruit)

just wanted to be pedantic :)