What is the design template for this?

I have a process similar to a workflow, suppose it is:

  • Training
  • Eat
    • Take your stuff to the basket
    • Table cleaning

Now, what I want to do, even the user cancels the "Eat" event, which I want them to "Clear the table", the same applies to the stages "Prepare" and "Take your stuff to the basket."

Currently, in my implementation, I had to perform several checks, and sometimes I end up calling the Clear Table twice, and some other branching problems, when I add a couple more steps.

Is there any well-defined design pattern for working with such flows? (AFAIR was alone, I just can't remember his name.)

+3
source share
5 answers

This is solved using the State pattern . If you check the drive, the logic goes smoothly.

+9
source

Sounds like a template template template .

Or you can do it using composition and strategy template .

If you have complex logic, then the State pattern might be better.

+7
source

++: > .

, , - (#, Java ..)

+3

#/.NET IDisposable. , - , , ( ).

Regarding the workflow aspect, I will just follow the WCF web service design pattern (i.e. Beginand Cancel). If you don't find this redundant for your circumstances, the Windows Workflow Foundation may be the best way.

+2
source

State Pattern my firend is what will end this work.

+1
source

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


All Articles