0

我面临一个问题,对于某些业务流程,调用业务对象和方法的顺序可能会经常更改。所以我想出了类似于下面的东西:(对不起,我无法发布图片......,我试图在下面的文字中表达它们)

业务对象: Object1、Object2

方法: M1、M2、M3、M4

进程: P1 (M1 > M2 > M3), P2 (M2 > M3 > if M3 return true then M4 else end)

在这种情况下,我使用的是 .NET 3.5。我创建了一些类来表示进程,其中包含我提到的那些序列。有用。但问题是每次流程更改时我都需要编译。如果我可以通过某种 XML 配置它会更好。

我听说过 jBPM for Java、Workflow Foundation for .NET,但不确定它们是否符合我的需求,或者它们是否会矫枉过正。我什至不知道在 Google 中搜索什么关键字。谁能建议我应该使用什么技术来解决这个问题?或者只是指向我一些网站或书籍?提前致谢。

4

1 回答 1

0

解耦软件层的一种常用方法是使用依赖倒置原则所述的接口。在您的情况下,您可以使用接口抽象流程概念并在该接口的实现中实现逻辑。当您需要更改流程的逻辑时,您可以创建该接口的新实现。您可以使用任何 IoC 框架来注入您想要使用的实现

下面显示了一个简单的方法来做到这一点:

 public interface IMethod
    {
        void M1();
        string M2();
        void M3();
        void M4();
    }

    public interface IProcess
    {
        IMethod Method { get; set; }
        void P1();
        void P2();
    }

    public class Process : IProcess
    {
        public IMethod Method
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        public void P1()
        {
            Method.M1();
            Method.M2();
        }

        public void P2()
        {
            if(Method.M2()==string.Empty)
            {
                Method.M3();
            }
        }
    }

    public class AnotherProcess : IProcess
    {
        public IMethod Method
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        public void P1()
        {
         Method.M4();
        }

        public void P2()
        {
            Method.M2();
            Method.M4();
        }
    }

    public class UseProcess
    {
        private IProcess _process;

        //you can inject the process dependency if you need use a different implementation

        public UseProcess(IProcess process)
        {
            _process = process;
        }

        public void DoSomething()
        {
            _process.P1();
        }
    }
于 2011-08-03T09:44:46.503 回答