I'm trying to make a database type program and wanted to know if I should use enums or classes to represent the properties of each item in the database.
I'll do other stuff later on, but to try out the coding side I'm using Pokemon as an example. So, my current idea is to have a Pokemon class. The basic instance variables that represent the properties of each Pokemon object are the first and second type. Type is, right now, its own class, and each type has the property of being weak to other types. This is represented by a list of other types. I don't know much about enums, but from what I've read they're good for when you need an unchangeable set of values, and I thought that that would be good for the types. However, when I was trying to define the list of weaknesses in the enum constructor, I ran into the problem of trying to add other types to the list when they hadn't been initialized yet.
Should I make Type a class instead of an enum? Should I make Pokemon an enum instead of a class?
import java.util.ArrayList;
public enum Type {
NORMAL,
FIGHTING,
FLYING,
POISON,
GROUND,
ROCK,
BUG,
GHOST,
FIRE,
WATER,
GRASS,
ELECTRIC,
PSYCHIC,
ICE,
DRAGON;
private String name;
private ArrayList<Type> weaknesses;
private Type(){
generateWeaknesses();
}
private void generateWeaknesses(){
switch(this){
case NORMAL:
weaknesses.add(FIGHTING);
break;
case FIGHTING:
weaknesses.add(FLYING);
weaknesses.add(PSYCHIC);
break;
case FLYING:
weaknesses.add(ROCK);
weaknesses.add(ELECTRIC);
weaknesses.add(ICE);
break;
case POISON:
weaknesses.add(GROUND);
weaknesses.add(BUG);
weaknesses.add(PSYCHIC);
case GROUND:
weaknesses.add(WATER);
weaknesses.add(GRASS);
weaknesses.add(ICE);
break;
case ROCK:
weaknesses.add(FIGHTING);
weaknesses.add(GROUND);
weaknesses.add(WATER);
weaknesses.add(GRASS);
break;
default:
break;
}
}
public ArrayList<Type> getWeaknesses(){
return weaknesses;
}
}