c# - Best way to provide params to a state transition in a FSM -
i'm in situation 1 of states in fsm needs information outside world job. information needs provided when transition requested. what's best way accomplish this? @ time i'm using fsm class blackboard share inforamtion between states.
one dirty solution have information cached in fsm , fill before requesting transition , let state have fsm black board. don't it.
my language c#
cheers.
to show meant passing delegate:
class mystatemachine { private readonly func<string> askforname; public mystatemachine(func<string> askforname) { this.askforname = askforname; } // ... void statetransitionforactionx() { var name = askforname(); // ... } } public mystatemachine createmachine() { return new mystatemachine ( () => { console.writeline("please, enter name: "); return console.readline(); } ); }
of course, can used data request whatsoever - using console seemed simple way illustrate idea :) closures in particular can pretty powerful.
Comments
Post a Comment