The state machine is very near at Design by contract pattern. There are states, preconditions and other stuff. The question now will be "Why developers never use design by contract pattern?" :)
https://github.com/nhatminhle/cofoja for example
https://github.com/nhatminhle/cofoja for example