您什么时候更喜欢使用状态机而不是线性工作流程

发布于 2024-08-20 11:28:10 字数 119 浏览 5 评论 0原文

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

在什么情况下您选择使用状态机以及在时间和复杂性方面减少了哪些类型的痛苦?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-08-27 11:28:10

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

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.

栩栩如生 2024-08-27 11:28:10

状态机工作流适用于工作流完成过程中没有预定义步骤的情况。查看此定义(来自 状态机工作流程Windows 工作流基础)

工作流是一个定义的过程,由实现所需行为的几个步骤组成。基本上有两种工作流程:顺序工作流程和状态机工作流程。在顺序工作流程中,工作流程中的所有进展决策均由工作流程本身做出。有一个明确定义的开始和明确定义的结束。两者之间有一个由分支和循环组成的流程来引导流程。这意味着工作流程处于控制之中。

对于状态机工作流程,对于某个解决方案要执行的所有步骤没有真正的预定义路径。状态机采用另一种方法。他们等待事件发生,并根据这些事件改变自己的状态。当决策来自外部应用程序且不可预测时,将使用状态机。因此,特别是当需要用户交互时,状态机是一个更方便的解决方案。

State machine workflows are meant to be used when there is no predefined steps through workflow completion. Take a look into this definition (from State Machine Workflows in Windows Workflow Foundation)

A workflow is a defined process consisting out of several steps which implement the needed behavior. There are basically two kinds of workflows: sequential workflows and state machine workflows. In sequential workflows all decisions to progress in the workflow are taken by the workflow itself. There’s a well defined start and well defined end. Between there’s a flow consisting of branches and loops to direct the flow. This means the workflow is in control.

With state machine workflows there’s no real predefined path of all steps to undertake for a certain solution. State machines take another approach. They wait for events to happen and based on these events they change their state. State machines are used when the decisions are coming in from an external application and are unpredictable. So especially when there’s user interaction needed a state machine is a more convenient solution.

累赘 2024-08-27 11:28:10

状态机和线性工作流程是完全不同的问题空间,在应用程序开发方面是不相关的。

建模的流程驱动该方法,您可以将状态机用于具有多个状态的流程,在这些状态中工作单元可以存在,并且在这些状态之间存在潜在的非线性进展。如果存在明显的线性流程,并且没有显着的回溯,则将使用线性工作流程(或顺序工作流程)。

State machine and linear workflow are sufficiently different problem spaces to be unrelated in terms of application development.

The process being modelled drives the approach, you use a state machine for a process that has a number of states in which the unit of work can exist and for which there is a potentially non-linear progression through the states. Where a clearly linear process exists, one for which there is no significant backtracking then a linear workflow (or sequential workflow) would be used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文