You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The purpose of implementing a state machine using Enums is so that the state doesn't have to be explicitly set.

Instead, the logic is provided on how to transition from one to the next.

State Machine Transition
public enum CmHandleState {

    Advised {
        @Override
        public CmHandleState nextState() {
            return Locked;
        }

        @Override
        public String cmHandleState() {
            return "ADVISED";
        }
    },
    Locked {
        @Override
        public CmHandleState nextState() {
            return Ready;
        }

        @Override
        public String cmHandleState() {
            return "LOCKED";
        }
    },
    Ready {
        @Override
        public CmHandleState nextState() {
            return this;
        }

        @Override
        public String cmHandleState() {
            return "LOCKED";
        }
    };

    public abstract CmHandleState nextState();
    public abstract String cmHandleState();


  • No labels