Sean's Note: Use Enum to implement finite state machine

2014年10月22日 星期三

Use Enum to implement finite state machine

範例:
public enum StateMachine {
 
    INITIAL {
        @Override
        public StateMachine next() {
            return SECOND;
        }
    },
    SECOND {
        @Override
        public StateMachine next() {
            return THIRD;
        }
    }
    // ... other states
    
    public abstract StateMachine next();
    
    // ... other methods
}

沒有留言:

張貼留言