1

I have an object which represents some document stored in a relational database (O/R mapping). This document has a status field which identifies its state. Every status (ie. entry, wait for approval, sent, paid etc...) carries it's own validation rules and requirements.

I'm wondering what is a correct OO implementation of such workflow. The easiest way of doing it is placing a bunch of if statements like

if (status == something || status == something else) check if the date can be changed();

but in a complex scenario this becomes extremely hard to read.

Suggestions for good design?

1
  • well the wf or life-cycle of your doc should not only exist in the UI level to enable/disable some buttons, it should be known also at Businee Logic level so that the logic can react properly and trigger certain actions. I would have a look at WF (Microsoft Workflow Foundation), it's configurable and should server the need (and even more) ;-) Commented Jan 16, 2012 at 10:35

2 Answers 2

2

Have a look at the Strategy Pattern. For each possible state you would create a class implementing the steps to perform.

Maybe you want to combine it with a Factory that builds the correct strategy object depending on the state of the doucment when it is read from the DB.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I'll look into it. Just a question if you're already familiar with it - Classes that represent each state are internal (nested in) to the document class?
I don't have enough knowledge of your concrete design, I wouldn't implement it that way (especially if the documents are persistent as in your case). The strategies should operate on the documents and modify them
Disadvantage of this approach as I see it is that all internals of Document class are hidden from a 'State' classes.
Disadvantage mentioned above is successfully solved by declaring strategy classes nested which will give them fully access rights to a parent class.
1

I think you need to review Windows Workflow Foundation. It's part of .NET and it's gives you ability to create workflows relatively easy.

2 Comments

Workflow will not change once it's implemented. I need an easy and clear way of implementation and introducing a new technology will not help in this regard IMO.
Just preview it and I'm sure boss/customer may like it...WWF just amazing thing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.