New to state machines and dotnet-state-machine.
I have a path that looks like this from Homed:
Homed -> Automatic -> Automatic.Paused (substate of automatic) -> Purge
Homed -> Automatic -> Purge
Homed -> Purge
Homed -> Manual -> Purge
The purge is EXACTLY the same in all four cases. The only difference is where they came from. If a transition is made from any state to purge then when purge is finished it needs to go back the the state it came from. A purge can only return back to the state it came from ... ever. It never can go to another state.
How is this normally done? It seems like I have two options:
Have one state "Purge" and keep track of where it came from so when it's time to go back I make the transition back to the state it came from.
-OR-
Do I have four discrete substates for purge where they are each of substate of the state it came from?
I have tried charting this out with Purge as a stand alone state and the chart is quite messy. I have found that in cases like these it helps to understand what the "normal" design pattern is.
Any help would be appreciated.
Either of the options you list here is valid. The separation of persistent variables, transitions, and states is essentially an implementation detail. Much as the use of a state machine for a particular problem is a choice.
Complete state diagrams often end up looking messy. I think it's a reflection of the nature of solving real problems.
My preference is to create new special-case Purge
states because I think it will result in easier code maintenance. And because hiding real-world complications (in a prior state variable for example) is not ideal unless you can abstract them away thoroughly.
Finally, the academic literature on state machines does not address a state's implementation. If we use a combination of persistent variables and an implementation function that is considered a unique state. So, if you carry around an integer variable that is important to your Purge
state for example, then academically you have as many Purge
states as valid values for your integer.