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?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.