I made a similar question a few days ago, but now I have new requirements and new tasks =). As usual, I use animal enumerations for didactic purposes, as soon as I don't want to explain domain specific things
I have a basic animal enumeration that is used by the entire zoo (I can add material to it, but must maintain compatibility):
public enum Animal {
DOG,
ELEPHANT,
WHALE,
SHRIMP,
BIRD,
GIRAFFE;
}
I need to classify them into several unrelated categories, such as gray animals (whale (my gray whale) and elephant), small animals (bird, shrimp and dog), marine animals (whale and shrimp).
I could, as suggested in my previous questions, add a lot of logic elements such as isGray, isSmall and isFromSea, but I need an approach in which I could store this somewhere else (so my enumeration is not necessary know a lot). Sort of:
public enum Animal {
DOG,
ELEPHANT,
WHALE,
SHRIMP,
BIRD,
GIRAFFE;
public boolean isGray() {
}
}
Somewhere else
public enum GrayAnimal {
WHALE,
ELEPHANT;
}
How is this possible? Am I asking too much from Java?