Say, I have some classes:
class NPC {
Attributes attributes;
Skills skills;
void doStuff() { //doStuffff }
}
class Player {
Attributes attributes;
Skills skills;
void doStuff() { //doStuffff }
}
And an Enum for these classes:
enum Attributes {
STRENGTH, INTELLIGENCE, AGILITY...//etc
}
enum Skills {
GUNS, MELEE, ATHLETICS...//etc
}
Now, let's say I wanted to make it so that each instance of either class Player or NPC could actually have their own separate instance of Attributes or Skills which could add and subtract values of the enums themselves. Is this possible? If not, would it be possible to use methods within an innter nested enum to manipulate the field values of a class it resides in?
This may sound somewhat insane, ridiculous, and just down right premadonnic, but when you have to find the right design solution...well, sometimes you just have to think outside the box.
Edit:
I found an interesting solution, though I doubt it's as good as the map idea.
I figured it'd just be interesting to post :D
public final class StatControl {
int agility;
int endurance;
int intelligence;
int intuition;
int luck;
int speed;
int strength;
}
enum Attributes {
AGILITY {
void add(int value) {
test.agility += value;
}
},
ENDURANCE {},
INTELLIGENCE {},
INTUITION {},
LUCK {},
SPEED {},
STRENGTH {};
abstract void add(int value);
StatControl test;
void receiveObj(StatControl test) {
this.test = test;
}
}
As you can see, a class holds an integer representation of the enums, but the enum itself acts as a control center which can manipulate whatever instance of the StatControl object passed to it.
Maps are probably better though - I could see where this could easily get messy.