Nezreli
Nezreli

Reputation: 1288

How to implement workflow within an object

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

Answers (2)

Alex Dn
Alex Dn

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

king_nak
king_nak

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

Related Questions