要使用的工作流设计模式的类型? [英] Type of workflow design pattern to use?

查看:133
本文介绍了要使用的工作流设计模式的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作流程顺序

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

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?

推荐答案

您可以查看petri-net实现,微积分启发的框架,如 Jacob ,用于进程的虚拟机,如 PVM 或状态机实现,如 SCXML ,尽管后者正在等待状态更改然后执行某些操作,因此您需要将控制流更改为数据流。

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);
}

这篇关于要使用的工作流设计模式的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆