I am currently writing a simple game library for personal use, and I’m having a massive brain fart on this one non-specific Java coding/OOP thing… Suppose I have an interface like this:
public interface Commandable {
public void command(Command cmd);
}
Assume that the Command class has only one field for now, which is “type”. Let’s say that, using my library, I write a Player class that implements Commandable. What I want is to be able to EXTEND Command to add new types at a later date, so .getType() can theoretically return a different set of “type” values than the Command superclass.
I wanted to use Enums, but since they are static and final, they make poor candidates. standard ints WORK, but generally speaking I try to avoid representing a type as an int whenever possible. The end goal is I want to be able to do something like this in the Player class:
@Override
public void command(Command cmd) {
if (cmd.getType() == Command.MovePlayerNorth) {
/* Do stuff here. */
}
}
Halp!