solrevdev
solrevdev

Reputation: 9033

Which C# design pattern would suit writing custom workflow in asp.net

Trying to find some examples on the intertubes. I am thinking of state or strategy pattern but if anyone has any war stories, examples or resources that they could point me to it would be appreciated.

I don't/can't use windows workflow.

My example is that i have a complex wizard that changes the state of the process based on what user is doing and by who the user is.

For example:

Cheers John

Upvotes: 2

Views: 6797

Answers (3)

Chris S
Chris S

Reputation: 65476

How about the State pattern (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)

As you can see, the pattern does fit exactly though.

Chain of Responsibility might be also be relevant if there's security concerns. If the wikipedia article makes no sense then this book has a good examples of both. Another is the Command pattern for wizards. None of them fit perfectly but they give you some good ideas to start with.

Upvotes: 6

James Poulose
James Poulose

Reputation: 3833

"Chain of Responsibility" is more or less similar to the work flow style. That is an awesome pattern to work with with immense flexibility options. I would strongly suggest you try that.

Upvotes: 0

amazedsaint
amazedsaint

Reputation: 7642

Design Pattern's are not specific to any language (C# design pattern?).

I suggest you should focus on building a framework for your workflow implementation, by using different patterns, instead of just thinking about an ideal pattern that may suit all your needs.

Recently read an article in Javaworld about using Dispatcher pattern to implement the workflow.

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

You might also consider evaluating alternate, existing open source workflow frameworks in C#, like NetBPM http://www.netbpm.org/

Upvotes: 0

Related Questions