I'm working on a Java library for sorts for Magic: the Gathering. Well, without going into a lot of detail, in the game there are five different colors of magic: white
, blue
, black
, red
, and green
. That's easy enough, that's a textbook example of an enum. However, there's a problem: there are several variations on these colors. There are your standard variants, the "monocolored hybrid" variants, and the "Phyrexian" variants (don't ask). So, my question is, which of these is a better approach?
Idea 1:
enum Symbol {
WHITE,
BLUE,
BLACK,
RED,
GREEN,
MONOCOLORED_HYBRID_WHITE,
MONOCOLORED_HYBRID_BLUE,
...
PHYREXIAN_WHTIE,
PHYREXIAN_BLUE,
...
}
Idea 2:
interface Symbol {
method1()
method2()
...
}
enum Primary implements Symbol {
WHITE,
BLUE,
...
}
enum MonocoloredHybrid implements Symbol {
WHITE,
BLUE,
...
}
enum Phyrexian implements Symbol { ...
I've been using the first way for a while, but I've been starting to think the second way might be better. It shows more clearly that these classes of symbols are different, yet still compatible, since they implement the same interface. It will cause a little bit of boilerplate code (just a couple fields), but my main issue is I have three enum constants called WHITE
. Now, I'd always be referencing them by their class name, e.g., Primary.WHITE
, but this still seems a little awkward. But perhaps it's better than the "Smurf naming" I'd have to do in the first technique. (I also can't use them in EnumMap/ EnumSet in the second way, but I think I'm okay with that.)
So, which is the better approach? Is it okay to have a bunch of enum classes all declaring constants with the same name? Is there a third alternative that's even better?