samedi 29 août 2015

handling large number of state transition

I have a class which has a property State.It's type is ObjectState enumeration.

ObjectState has near 30 different values that an object can only be in one of these state.

I managed to check validity of state transition between different state with 'if' statements:

if (currentState == ObjectState.SomeState && 
      nextState == ObjectState.AnotherState &&
      someOtherCondition)
{
   ....
} // many of these if statements since there are near 80 different transitions

As number of states grows the code is somehow hard to understand and managing valid transition is getting harder. What should I do?

If object is in a specific state, next state will be determined by just nextState variable and if this transition is valid then object state will change to nextState.

Aucun commentaire:

Enregistrer un commentaire