When you prefer using state machines over linear workflows

State machines can reduce the complexity of workflows by having multiple loops and branching or logic, when the workflow needs to β€œrespond” to the answers provided by users. This will be an event driven workflow.

In what circumstances did you decide to use a state machine and what pain has decreased in terms of time and complexity?

+4
source share
3 answers

State machines are really good for event driven code. You cannot use loops and branches if your code is called as a response to an event. You will need to use the state machine to associate events with it in order to change state, and the event handler responds according to the current state of the machine.

+4
source

The work processes of state machines are intended to be used when there are no predefined steps to complete the work process. Take a look at this definition (from State Machine Workflows to Windows Workflow Foundation )

A workflow is a specific process consisting of several steps that implement the necessary behavior. Basically, there are two types of workflows: sequential workflows and workflows in state machines. In sequential workflows, all decisions for progress in the workflow are made by the workflow itself. This is a well-defined start and a well-defined end. Between theres a stream consisting of branches and loops to direct the stream. This means that the workflow is under control.

When working with work processes of finite state machines, there is no real predetermined path for all steps to make a specific decision. State machines take a different approach. They are waiting for events, and on the basis of these events they change their state. State machines are used when decisions come from an external application and are unpredictable. Therefore, especially when user interaction is required, the state machine is a more convenient solution.

+4
source

Machine condition and linear workflow are quite different problem spaces that are not interconnected in terms of application development.

When modeling a model, an approach is applied, you use a state machine for a process that has several states in which a unit of work may exist and for which there is a potentially non-linear progression through states. Where there is a clearly linear process for which there is no significant departure, then a linear workflow (or sequential workflow) will be used.

+3
source

Source: https://habr.com/ru/post/1300047/


All Articles