代码之家  ›  专栏  ›  技术社区  ›  solrevdev

哪种C#设计模式适合在asp.net中编写自定义工作流

  •  2
  • solrevdev  · 技术社区  · 17 年前

    试图找到一些关于互斥的例子。我正在考虑国家或战略模式,但如果任何人有任何战争故事,例子或资源,他们可以告诉我,将不胜感激。

    我不/不能使用windows工作流。

    例如:

    • 取消
    • 用户请求
    • 经理的要求
    • 裁判
    • 管理员收到
    • 管理员取消

    干杯

    3 回复  |  直到 17 年前
        1
  •  6
  •   Chris S    14 年前

    State 图案( wikipedia link )?

    public abstract class State
    {
        /// <summary>
        /// Holds the current state we're in.
        /// </summary>
        public State CurrentState
        { 
            get; 
            set; 
        }
    
        public virtual string Cancelled(State context)
        {
            return "";
        }
    
        public virtual string RequestedByUser(State context)
        {
            return "";
        }
    
        public virtual string RequestedByManager(State context)
        {
            return "";
        }
    }
    
    public class CancelledState : State
    {
        public override string Cancelled(State context)
        {
            context.CurrentState = new SittingState();
            return "Cancelled.";
        }
    
        public override string RequestedByUser(State context)
        {
            context.CurrentState = new RequestedByUserState();
            return "Requested by User.";
        }
    
        public override string RequestedByManager(State context)
        {
            return "You can't do this before it's been requested by the User";
        }
    }
    
    // (RequestedByUserState and RequestedByManagerState classes have been cut out)
    

    正如你所看到的,这种模式确实非常适合。

    Chain of Responsibility 如果存在安全问题,也可能与此相关。如果维基百科的文章毫无意义那么 this book 两者都有很好的例子。另一个是向导的命令模式。它们都不完美,但它们给了你一些好主意。

        2
  •  0
  •   amazedsaint    17 年前

    设计模式并不特定于任何语言(C#设计模式?)。

    看见 http://www.javaworld.com/javaworld/jw-10-2001/jw-1019-dispatcher.html

    您也可以考虑在C语言中评估替代的、现有的开源工作流框架,比如NetBPM。 http://www.netbpm.org/

        3
  •  0
  •   James Poulose    14 年前