在 OOP 中实现有限状态自动机
我正在考虑用 Java 或 C++ 等 OOP 语言实现具有有限状态自动机的程序。
对于良好的软件设计,您认为通过可管理数量的可用状态来实现此目的的最佳方法是什么?
为每个州实施一个自己的类好吗? 如果是,如何在两个状态之间建立桥梁?
感谢您的任何评论!
I am thinking about implementing a program with finite state automaton in an OOP language like Java or C++.
What would you think is the best way to implement this with a manageable amount of available states, regarding to good software design?
Is it good to implement for each state an own class?
If yes, how to do the bridge between two states?
Thanks for any comment!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这只是为了展示你的编程能力,还是为了一个实际的项目等等?无论哪种情况,都取决于您想要状态机的用途:
- 是为了管理某种工作流程中的任务
- 是否确定应用程序流程状态
- 是否用于业务规则引擎等
在项目的情况下,我建议,根据您的目标用途,您在该域中寻找库。例如,Java 有很多用于工作流/业务流的库,以及大量的规则引擎(Drools 立刻浮现在脑海中,尽管它是一个复杂的庞然大物)
Is this just to flex your programming muscle, or for an actual project etc? In either case it depends on what you want the state machine for:
- is it to manage tasks in some sort of workflow
- is it to determine application flow state
- is it for a business rules engine etc
In the case of a project, I would suggest that, depending on what your target use is, you look for libraries in that domain. Java for example has MANY MANY libraries for workflow/busines flows, as well as tons of rules engines (Drools comes to mind right of the bat, although it is a complex behemoth)
试试这个 - 关于设计的部分很好,它展示了 fsm 的用途
http://www.ibm.com/developerworks/library/wa-finitemach1/< /a>
我见过的另一个用途是为计算机服务实现托管对象,通过“开始”转换将对象从“向下”状态移动到“启动”状态等,使用 OMG 托管对象生命周期的扩展 -循环
Try this - the section on design is good and it shows a use for a fsm
http://www.ibm.com/developerworks/library/wa-finitemach1/
Another use I've seen is to implement managed objects for a computer service, with the transition "start" moving the object from the "down" to the "starting" state etc using an extennsion of the OMG managed object life-cycle
dk.brics.automaton 库是 FSA 在 Java 中的良好实现。它在构建时考虑到了性能,因此它牺牲了一些 OOP 原则来换取速度,但我建议您看一下它。
The dk.brics.automaton library is good implementation of FSA's in Java. It's build with performance in mind, so it trades in some OOP principles for speed, but i'd recommend you take a look at it.