I started to implement a system with a state machine. But I came to a point where I doubt that a state machine is the correct approach.
For example: I have four states:
(idle, powerup, powerdown, work)
and two other states:
(production, test)
powerup and powerdown do behave different in production and test state ...
If I do have more states the combination of states explodes ...
How is this solved with a state machine?
That's a bit difficult to answer since the actual use case is very vague, but here are some possible techniques:
Pros: straightforward.
Cons: cluttered, does not scale well, if some of the state logic is shared across instances there will be some copy pasta involved (hence, not very maintainable)
So in your example, you would have a Production/Test state machine, and each one will implement it's own Idle/Powerup/Powerdown/Work state machine internally.
If you think this over, this is actually a neater implementation of option 1.
Pros: more readable than option 1
Cons: assuming substates should share some common logic, there will still be copy pasting involved
In your example, your agent or system will a container of the above mentioned state machines and process them in turn. The Production/Test machine would write some status to a shared memory that the other machine will read from and branch it's state logic accordingly.
Pros: Can share code between different states
Cons: Can share code between different states... Ok, serioulsy, it's super important to empashize that sharing code is NOT always a good idea (but that's a whole other phylosophical discussion. Just make sure you properly evaluate the amount of shared code vs. the amount of unique code or paths so you don't end up with a huge class that essentially contains 2 completely separate code paths