The power of enums
So as Java developers, we're constantly told to favor using enums over constants, but why? And how does this then work? Basically, by using enums, we can give each type instance its own state, and its own behavior. public interface LightState { String getMessage (); void turnOn ( Light light ); void turnOff ( Light light ); } For example in the above snippet, we declare the behavior of a light. Implementing this as an enum could be written as public enum LightStateAsEnum implements LightState { ON ( " Lights are on. " ) { @Override public void turnOff ( Light light ) { light . setState( OFF ); } }, OFF ( " Lights are off. " ) { @Override public void turnOn ( Light light ) { light . setState( ON ); } }; private final String message; private LightStateAsEnum ( String message ) { this . message = message; } @Override public String getMessage () { return message; } @Override public voi...