与线性工作流相比,何时更喜欢使用状态机 [英] When do you favor the use of state machines over linear workflows

查看:133
本文介绍了与线性工作流相比,何时更喜欢使用状态机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当工作流必须响应用户提供的答案时,存在多个循环和分支或逻辑时,状态机可以降低工作流的复杂性。这将是一个事件驱动的工作流程。

State machines can reduce complexity of workflows when there are multiple loops and branching or logic when the workflow must "react" to answers supplied by users. This would be an event-driven workflow.

在什么情况下您选择使用状态机,并且在时间和复杂性方面减轻了哪种痛苦?

In what circumstances have you elected to use a state machine and what type of pain did reduce in terms of time and complexity?

推荐答案

状态机非常适合事件驱动的代码。如果您的代码是作为对某个事件的响应而调用的,则不能使用循环和分支。您必须使用状态机,将事件馈入状态机以更改状态,并使事件处理程序根据该机的当前状态做出反应。

State machines are really nice for event-driven code. You can't use loops and branches if your code is being invoked as a response to some event. You'll have to use a state machine instead, feed the events into it to change the state, and have the event handler react according to the machine's current state.

这篇关于与线性工作流相比,何时更喜欢使用状态机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆