I have an application whose core design is based on a state machine that uses one-way transitions. This design works well for most scenarios and required features; however the application requires an additional "undo" feature that is available during some of the states. Since many states can have transitions to a single state, this undo feature forces me to keep track of the previous state. To go back to the previous state, I can either:
- force the previous state that I kept, regardless of existing transitions or:
- create many new "undo" transitions to previous states, and choose the correct undo transition according to the previous state
As I currently see it, both options somewhat break the state machine concept. The second option is less violent but perhaps more clumsy in an "if-else" matter and more vulnerable to bugs.
Which option do you think is preferable? I would love to hear other ideas if you have any.
I am currently using the second suggested method, but it's quite ugly and requires some maintenance