I’m working on a status changing implementation for records. For example, when a record is created, it commences in a ‘pending’ state until a administrator changes its state to either ‘active’, ‘rejected’ or ‘revoked’.
The thing is, if a status has been changed from pending to active, the status cannot be changed back to pending or rejected. A rejected status can be changed back to active.
A revoked status cannot changed to active, pending or rejected. At the moment I have a series of if/else statements to detect this but I wondered if there was a more logical and standard approach.
You could have an array with all the allowed transitions:
You could do something a little more complicated that could detect that if can go from A to B and you can go from B to C, then you can go for A to C (if that’s something you want). See reachability in the context of graph theory.