I have been trying to implement a state machine with Kotlin as part of my SpringBoot application. I have essentially the following:
a State class containing all the states
a Trigger Class (action that triggers a change of state)
a Transition class that essentially takes an initial state, action and final state
and a TransitionConfiguration holding all allowed transitions
I am struggling with writing the actual state machine class. Since it is part of my SpringBoot app and I need to be able to get hold of the entity/dto will be inside my service, however I am not sure how to go about. In particular, I am not sure how to write the method, which is what it should actually apply the state change. Can you help? Can you provide any indication of what that would look like?
You can ignore Spring for most of this. If you want to store the machine's current state in a database, just write it on top of an interface that is responsible for storing and retrieving the current state and let Spring inject it.
I don't really know Kotlin, but in Java I would write something like this:
Always look on the bright side of life. At least this ad is really tiny: