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?
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.
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);
}
You can try activiti. You can also design your own workflow using the eclipse plugin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With