Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of workflow design pattern to use?

I have a workflow that goes in sequence

A - > B - > C - > D - > E

I need a design pattern that allow me to add a state in between them with least code change.

http://en.wikipedia.org/wiki/Workflow_patterns

Which of these design pattern works?

like image 797
seesee Avatar asked Jul 24 '13 08:07

seesee


People also ask

What is a workflow design pattern?

Workflow patterns are concepts of economised development. Their usage should follow strategies of simplifying maintenance and reducing modelling work. Workflow is performed in real time. The mechanisms of control must support the typical pace of work. Design patterns must delay execution of workflow.


Video Answer


2 Answers

You could look into petri-net implementions, calculus-inspired frameworks like Jacob, virtual machines for processes like the PVM or a statemachine implementation like SCXML although the latter are waiting for state changes and then do something, so you need to sort of change your control flow into data flow.

If you want to implement it yourself, you need to make sure that you give the control back to some runtime controller instead of just calling the next node, because that would blow your stack. This runtime controller could also inject a context object into the activity runnables and that way you can share state between the activities. Please find a rough sketch as pseudo code below:

interface Activity {
    Activity run(SharedContext context);
}

class A implements Activity {
    public Activity run(SharedContext context) {
        doA(context);
        return new B();
    }
}

class B implements Activity {
    public Activity run(SharedContext context) {
        doB(context);
        return new C();
    }
}

// runtime controller
SharedContext context = new SharedContext();
Activity next = new A();

while (next != null) {
    next = next.run(context);
}
like image 183
vanto Avatar answered Sep 29 '22 15:09

vanto


You can try activiti. You can also design your own workflow using the eclipse plugin

like image 22
Rakesh Avatar answered Sep 29 '22 17:09

Rakesh