Created
July 24, 2013 08:05
-
-
Save chrisdew/6068800 to your computer and use it in GitHub Desktop.
enum state machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IState { | |
public void GuiBookOn() throws InvalidStateException; | |
public void GuiBookOff() throws InvalidStateException; | |
public void NetBookedOn() throws InvalidStateException; | |
public void NetBookedOff() throws InvalidStateException; | |
} | |
public enum State implements IState { | |
BOOKED_OFF { | |
@Override | |
public void GuiBookOn() throws InvalidStateException { | |
// send book on message | |
changeState(BOOKING_ON); | |
} | |
}, BOOKING_ON { | |
@Override | |
public void NetBookedOn() throws InvalidStateException { | |
changeState(DESKTOP); | |
} | |
}, DESKTOP { | |
@Override | |
public void GuiBookOn() throws InvalidStateException { | |
// send book off message | |
changeState(BOOKING_OFF); | |
} | |
}, BOOKING_OFF { | |
@Override | |
public void NetBookedOn() throws InvalidStateException{ | |
changeState(BOOKED_OFF); | |
} | |
}; | |
public static State state = BOOKED_OFF; | |
private static void changeState(State newState) { | |
// inform listeners, maybe emit intents? | |
state = newState; | |
} | |
public void GuiBookOn() throws InvalidStateException { throw new InvalidStateException(); }; | |
public void GuiBookOff() throws InvalidStateException { throw new InvalidStateException(); }; | |
public void NetBookedOn() throws InvalidStateException { throw new InvalidStateException(); }; | |
public void NetBookedOff() throws InvalidStateException { throw new InvalidStateException(); }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment