Synchronization of two state machines

Let's say I'm creating a business process management application. It has the following entities: problems and tasks related to each other as one problem for many tasks. Both the task and the task have their own states, and the state of one can influence the state of the other.

For example, both of them have the states "Canceled" and "Completed". When I change the status of the question to "Canceled", all of its tasks should become "Canceled". When I change the status of all tasks to Completed, the problem should automatically become Completed.

Suppose that for both objects there are quite a few states and the logic of transitions from one state to another, and the dependence of the states can change, are there any design patterns and / or best methods for handling this situation?

+4
source share
2 answers

A design pattern that catches your eye is the "rule"; -)

Or, if you want, a command template

In other words, for such situations, I would create a database table that lists the states and valid transitions, and map the action to each transition (using reflection)

I found this useful for handling cases where the transition action is more complex than just updating statuses to match.

For example, in one system, we had a workflow in which a request document had to go through several committee review stations, each of which could reject or transmit the document to the next stage, and also perform a selective side effect. The organization of the committee, the processing and processing structures changed significantly three times during development and five more times in the first year of deployment.

+2
source

I prefer the observer pattern for these kinds of things: http://en.wikipedia.org/wiki/Observer_pattern In the above example, I will have tasks to observe their problems and problems fulfill their tasks. When a problem is marked canceled, tasks see and mark themselves canceled. When a task is marked completed, the problem sees it and checks if other tasks are completed, etc.

+2
source

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


All Articles