Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
@Will, you were absolutely right.
GUARD - fires tests that may abort the transition without leaving the old stateEXIT - stuff that always happens when you leave this old state'Transition-specific note' [your jargon] / 'ACTION' [my jargon] - do specific stuff for this transitionENTRY - welcome to the new state, wherever you have come fromCHANGED - (Cough) I don't see what this is for... How does it differ from ENTRY? Why two?W
GUARD isn't necessary. If you want to cancel a transition do it from a command triggered by the exiting note, by sending a StateMachine.CANCEL note.
StateMachine.CHANGED is broadcast at the end of every single state change and allows you to monitor the machine's behavior without signing up for every state-specific 'changed' note. Trust me you need both.
WRT performing guard logic in the exiting note [...]
As for 'never querying state' its not a query, its a notification.
Don't confuse the GoF State pattern with the StateMachine utility, they are completely different things.
To compare with another well-known state machine design.
: <state name="TOP_LEFT"> <transition action="TO_TOP_RIGHT" target="TOP_RIGHT" /></state><state name="TOP_RIGHT"> <transition action="TO_BOTTOM_RIGHT" target="BOTTOM_RIGHT" ></state>//...
<state name="TOP_LEFT"> <transition action="TO_TOP_RIGHT" target="TOP_RIGHT" /></state><state name="TOP_RIGHT"> <transition action="TO_BOTTOM_RIGHT" target="BOTTOM_RIGHT" ></state>//...
// In a Mediator somewhereoverride public function handleNotification(note:INotification):void { switch (note.getName()) { case StateMachine.CHANGED: // Have to test the FSM's current state if ((note.getType() == TOP_RIGHT) { viewComponent.doMoveRight() } else if ((note.getType() == BOTTOM_RIGHT) { viewComponent.doMoveDown() //...
// FSM<state name="TOP_LEFT"> <transition action="TO_TOP_RIGHT" target="TOP_RIGHT" effect=CMD_MOVE_RIGHT/></state><state name="TOP_RIGHT"> <transition action="TO_BOTTOM_RIGHT" target="BOTTOM_RIGHT" effect=CMD_MOVE_DOWN></state>//...
override public function handleNotification(note:INotification):void { switch (note.getName()) { case CMD_MOVE_RIGHT: // Don't care about the FSM's current state viewComponent.doMoveRight(); break; case CMD_MOVE_DOWN: viewComponent.doMoveDown(); break; //...
<state name="TOP_LEFT"> <transition action="TO_TOP_RIGHT" target="TOP_RIGHT" /> <transition action="TO_BOTTOM_LEFT" target="BOTTOM_LEFT" /></state>//...
// In a Mediator somewhereoverride public function handleNotification(note:INotification):void { switch (note.getName()) { case StateMachine.CHANGED: // Have to test the FSM's current state if ((note.getType() == TOP_RIGHT) && viewComponent.currentPos() == TOP_LEFT) { viewComponent.doMoveRight(); } else ((note.getType() == TOP_RIGHT) && viewComponent.currentPos() == BOTTOM_RIGHT) { viewComponent.doMoveUp(); } else // Tons more modified code here... //...
<state name="TOP_LEFT"> <transition action="TO_TOP_RIGHT" target="TOP_RIGHT" effect=CMD_MOVE_RIGHT/> <transition action="TO_BOTTOM_LEFT" target="BOTTOM_LEFT" effect=CMD_MOVE_DOWN /></state>//...