有人用过“状态机”吗? 就像您项目中的架构一样?
定义发生某事时要做的一切,
我真的很感激,
但还没有尝试过。
我的问题是: 如何设计基于状态机的系统?
Define everything to do when something happens,
I really appreciate that,
but never have tried that yet.
my Q is :
How to design a state machine based system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“状态事件”驱动的架构被用于相当多的应用领域。 事实上,有一个名为 smc(状态机编译器)的工具,它采用状态机规范(就像 lex 和 yacc 接受扫描器和解析器定义)并生成 C 或其他语言的代码来实现它。
'State-event' driven architecture is used in quite a few application domains. In fact, there is a tool called smc (State Machine Compiler) that takes a specification for a state machine (much like lex and yacc take scanner and parser definitions) and generates code in C or other languages to implement it.
您看过状态模式吗? 也在这里。 Apache Commons SCXML 可能对您也有用。
Have you looked at the State Pattern? Also here. Apache Commons SCXML might also be useful to you.
根据我的经验,状态机的基础是 switch 语句。
其中的每个案例代表机器的一种状态。
switch 语句需要定期调用,这可以在编码循环内或在事件处理程序内。 这实际上取决于您的状态机正在做什么,以及您希望软件如何运行或反应。
您可以从 case 语句中更新状态变量以更改状态。
The basis of a state machine, in my experience, is the switch statement.
Each case within that represents a state of your machine.
The switch statement needs to be called on a regular basis, this can be within a coded loop, or within an event handler. It really depends on what your state machine is doing, how you want your software to run or react.
You update the state variable from within a case statement in order to change state.
无数的小混蛋。
我建议你先查一下有限状态机的理论基础,了解它们适合什么样的任务。
http://en.wikipedia.org/wiki/Finite 状态机 是一个好地方开始。
Tons and tons of the little buggers.
I suggest that you look up the theoretical basis of finite state machines first and understand for what kind of tasks they are suitable for.
http://en.wikipedia.org/wiki/Finite state machine is a good place to start.