I want to simulate a kind of FSM (state machine). I have a sequence of states (say, from StateA to StateZ). This sequence is called a chain and is implemented internally as a List. I will add the states in the order I want them to execute.
My goal is to make a sequence of actions on my computer (e.g. mouse clicks). (I know this has been done a million times).
So, the state is defined as:
boolean Precondition()<- Checks if there is any condition for this state. For example, if I want to press the "Record" button of a program, in this method I would check if the program process is working or not. If so, go to the next state in the list of chains, otherwise go to what was defined as a failure state (usually this is the first state of all).IState GetNextState()<- Returns the next state for evaluation. If the Precondition () condition was successful, it should lead to the next state in the chain, otherwise it should lead to a failure state.Run()It just checks Precondition()and sets the internal data, so it GetNextState()works as expected.
So, a naive approach to this would be something like this:
Chain chain = new Chain();
//chain.AddState(new State(Precondition, FailState, NextState) <- Method structure
chain.AddState(new State(new WinampIsOpenCondition(), null, new <problem here, I want to referr to a state that still wasn't defined!>);
, , . , -, ?
, , , .