状态机和⼯作流的区别

状态机和⼯作流的区别

都是流程的管理,⼯作流引擎和状态机到底区别在哪⾥。

Introduction

When companies decide to implement a system that will help them manage business processes, their choice will probably lie between a workflow engine and a state machine. Though the behavior of the two systems seems to be quite similar, they both have a number of distinct features. Accordingly, it is necessary to analyze the pros and cons of both to decide which of the systems suits most company’s needs.

当公司决定实现⼀个系统来帮助他们管理业务流程时,他们的选择很可能位于⼯作流引擎和状态机之间。虽然这两个系统的⾏为看起来很相似,但是它们都有许多不同的特性。因此,有必要分析两者的利弊,以决定哪⼀个系统适合⼤多数公司的需要。

In general, the major difference between a workflow engine and a state machine lies in focus. In a workflow engine, transition to the next step occurs when a previous action is completed, whilst a state machine needs an external event that will cause branching to the next activity. In other words, state machine is event driven and workflow engine is not.

⼀般来说,⼯作流引擎和状态机的主要区别在于焦点。在⼯作流引擎中,在完成之前的操作时,就会切换到下⼀个步骤,⽽状态机需要⼀个外部事件,这将导致分⽀到下⼀个活动。换句话说,状态机是事件驱动的,⽽⼯作流引擎不是。

What to Consider When Making a Choice

When trying to figure out which of the two systems to implement, it is necessary to analyze some of their major features.

当试图找出要实现的两个系统中的哪⼀个时,有必要分析它们的⼀些主要特性。

Flexibility

Workflow engine supports sequential pattern when tasks are executed one after another. The next step in a workflow will not start till the previous is finished. For instance, the document will not be signed by the boss till the lawyer signs it. As a result, workflow engine seems to be rigid and deterministic in its nature. State machine, on the contrary, works asynchronously. Since the steps in the machine are triggered by certain events/actions, they shouldn't necessarily be performed in a strict order. From this point of view state machines are more flexible.

However, the situation changes once your company has new business requirements. Imagine a state machine that has the following three states: submit an application, accept an application and reject an application. At present, we can see three separate states and clear transitions to them. Later on you decide to add some new states, for example, change an application and ask for feedback. In this situation the number of states and transitions between them increases considerably. Moreover, when adding new states, you should understand that you cannot change one without breaking the rest. As a result, instead

of simply adding new functionality, you find yourself building a new system from scratch. Therefore, when you understand

that your business rules may change over the time (that is practically inevitable process), workflow engine is a better option.

当任务逐个执⾏时,⼯作流引擎⽀持顺序模式。⼯作流的下⼀个步骤将在完成之前才开始。例如,该⽂件将不会由⽼板签署,直到律师签字。因此,⼯作流引擎在本质上似乎具有刚性和确定性。相反,状态机的⼯作是异步的。由于机器中的步骤是由某些事件/动作触发的,所以不应该严格执⾏它们。从这个⾓度看,状态机更灵活。

但是,⼀旦公司有了新的业务需求,情况就会发⽣变化。假设有以下三个状态的状态机:提交应⽤程序、接受应⽤程序和拒绝应⽤程序。⽬前,我们可以看到三个独⽴的国家和明确的过渡。稍后,您决定添加⼀些新状态,例如,更改应⽤程序并请求反馈。在这种情况下,它们之间的状态和转换的数⽬会⼤⼤增加。此外,在添加新状态时,您应该了解,您不能在不破坏rest的情况下更改⼀个状态。结果,您发现⾃⼰从头开始构建⼀个新的系统,⽽不是简单地添加新功能。因此,当您理解您的业务规则可能在时间上发⽣变化(这实际上是不可避免的过程)时,⼯作流引擎是⼀个更好的选择。

Understandability

State machines appear to be easy in usage at first sight. The developer simply needs to review company's processes and draw a diagram on which he should depict a particular number of states and events that will trigger transitions to them. However, the main problem of a state machine is that in practice it suits only businesses with one-dimensional problems. It serves well for projects with several distinct states, but fails when there are more complex systems. A typical CRM system built as a sequence of states might cause many problems. You’ll have to think of numerous status transitions, such as the

registration of a new lead, start of the project or cancellation. Moreover, each of these states could be divided into separate ones as well. For example, you might want to define a reason for cancellation or through which channel a new lead was found (an email campaign, cold calling, etc.). When trying to depict each of these states, the system soon becomes unmanageable.

状态机乍⼀看似乎很容易使⽤。开发⼈员只需要回顾公司的流程,并绘制⼀个图表,其中他应该描述特定数量的状态和事件,这些状态和事件将触发对它们的转换。然⽽,⼀个状态机的主要问题是,在实践中它只适合有⼀维(相对多个维度)问题的业务。它为具有⼏个不同状态的项⽬提供了良好的服务,但是当有更复杂的系统时就会失败。⼀个典型的由状态序列构建的CRM系统可能会导致许多问题。您将不得不考虑许多状态转换,⽐如注册⼀个新的领导,启动项⽬或取消。此外,每个州也可以被划分为独⽴的州。例如,您可能想要定义⼀个取消的原因,或者通过哪个通道找到新的线索(邮件活动、冷调⽤等等)。当试图描述这些状态时,系统很快变得难以管理。

Workflow engines seem to be quite complicated at first, since additional elements should be deployed. However, for larger systems it is the most appropriate solution. When implemented properly, benefits outweigh apparent complexity. Workflow engine seems to be a better model for business process management. It is often used for task management systems, being able to quickly allocate tasks to various executors. Moreover, workflow engines usually have solid documentations. A new developer will be able to understand it without spending hours analyzing endless lines of code.

⾸先,⼯作流引擎似乎相当复杂,因为应该部署更多的元素。然⽽,对于较⼤的系统,它是最合适的解决⽅案。当实现适当的时候,好处⼤于明显的复杂性。⼯作流引擎似乎是⼀个更好的业务流程管理模型。它通常⽤于任务管理系统,能够快速地分配任务给不同的执⾏者。此外,⼯作流引擎通常有可靠的⽂档。⼀个新的开发⼈员将能够理解它,⽽不⽤花费数⼩时分析⽆穷⽆尽的代码。

Readability

Effective collaboration between people inside and outside the company is necessary for businesses development. Therefore, a common platform, used by a company, should be clear for all the members of the staff. Managers should be able to quickly identify at which state a certain action is at any given time.

State machine often fails in terms of readability. It is capable of executing only one state at a time since it is impossible to run two in parallel. So, when you try to introduce events that might happen under certain conditions, you double the number of states. When the number of states becomes too large, readability of state machine tends to zero.

公司内部和外部⼈员之间有效的协作是企业发展的必要条件。因此,⼀个公司使⽤的公共平台应该对所有员⼯都是透明的。管理⼈员应该能够快速识别某个特定动作在任何给定时刻的状态。

状态机在可读性⽅⾯常常失败。它能够⼀次只执⾏⼀个状态,因为不可能同时运⾏两个状态。所以,当你试着介绍在某些情况下可能发⽣的事件时,你会把状态的数量翻倍。当状态数变⼤时,状态机的可读性趋于零。

Predictability

Workflow engines, in comparison to state machines, are predictable in their nature. They use conditions that are always predefined at the beginning. Let's assume that you require document approval from both direct manager and general manager. The document may be signed in any order. If you choose a workflow engine, this process will be predefined. For instance, at first the direct manager signs the document, then the general manager. Accordingly, the general manager will not receive the document till the direct manager signs it. This process cannot be changed.

In a state machine pattern, it is the user who decides whether the direct or the general manager should sign the document first. In this case the decisions are made by people. Since state machines are controlled by external factors, there could be numerous events that will lead to process completion. From this point of view, workflow engine is more beneficial as it guides you throughout the whole process.

与状态机相⽐,⼯作流引擎在本质上是可预测的。它们使⽤在开始时总是预定义的条件。假设你需要得到直接经理和总经理的书⾯批准。该⽂件可

以以任何顺序签署。如果您选择⼀个⼯作流引擎,这个过程将是预定义的。例如,⼀开始直接管理⼈员签署⽂件,然后是总经理。因此,总经理将不会收到⽂件,直到直接经理签字。这个过程是不能改变的。

在状态机模式中,由⽤户决定直接或总经理是否应该⾸先签署⽂档。在这种情况下,决策是由⼈做出的。由于状态机是由外部因素控制的,所以可能会有许多事件导致过程的完成。从这个⾓度看,⼯作流引擎更有益,因为它指导您整个过程。

Conclusion

State machine is a good solution if your system is not very complex. You may implement it if you are capable of drawing all

the possible states as well as the events that will cause transitions to them. In general, state machines work well for network protocols or some of the embedded systems.

Workflow engine implementation is a good way of managing business processes. It is the right solution for task allocation, CRM and other complex systems. All in all, its ultimate goal is to improve business processes and company’s efficiency. That is why it perfectly suits for business process automation.

如果您的系统不是很复杂,状态机是⼀个很好的解决⽅案。如果您能够绘制所有可能的状态以及将导致转换的事件,您可以实现它。⼀般来说,状态机在⽹络协议或某些嵌⼊式系统中运⾏良好。

⼯作流引擎实现是管理业务流程的好⽅法。它是任务分配、CRM和其他复杂系统的正确解决⽅案。总之,它的最终⽬标是改善业务流程和公司的效率。这就是为什么它⾮常适合业务流程⾃动化。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值