Firstly I assume that Java Enums should conform to the same practices as regular classes.
I'm a little hazy on the meaning of "Single responsibility". With the following code, I'm wondering if the hasSucceed
method is the violation as it's logic goes beyond the purpose of holding the Level.
If it does violate the principle, how would I refactor?
package foo;
public enum Level {
AWFUL(-4),
TERRIBLE(-3),
POOR(-2),
MEDIOCRE(-1),
FAIR(0),
GOOD(1),
GREAT(2),
SUPERB(3),
LEGENDARY(4);
private final int level;
Level(int level) {
this.level = level;
}
public int getValue() {
return this.level;
}
public boolean hasSucceeded(Level requiredLevel, Level roll) {
return getValue() + roll.getValue() >= requiredLevel.getValue();
}
}