3 ms·
A state machine has states and transitions. Some transitions are valid, others are not. Therefore when you implement a state machine in code the consequence is
by partycoder 10y ago
A state machine has states and transitions.
Some transitions are valid, others are not.
Therefore when you implement a state machine in code the consequence is sequential coupling.
Imagine a car class: You have StartCar(), Accelerate(), Break(), StopCar(), SwitchGear(). Can you accelerate with your car turned off? no. Can you stop your car twice? No.
So there should be validations in state transitions. Since in this code those are missing, it's possible to arrive to invalid states that can cause undesired behavior.
In the "request" npm module (an ambiguous module name that wastes a lot of my time in a regular basis), you can abort a request that has not started. That causes an exception. It took me a lot of time to find it. It was all because of a broken state machine.