Reputation: 1288
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?
Upvotes: 1
Views: 1163
Reputation: 5553
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.
Upvotes: 1
Reputation: 11513
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.
Upvotes: 2