Domain models¶
If you need to use any other object to persist the current state, or you’re using the
state machine to control the flow of another object, you can pass this object
to the StateMachine
constructor.
If you don’t pass an explicit model instance, this simple Model
will be used:
1class Model:
2 def __init__(self):
3 self.state = None
4 """Holds the current :ref:`state` value of the :ref:`StateMachine`."""
5
6 def __repr__(self):
7 return f"Model(state={self.state})"
See also
See the Order control machine (rich model) as example of using a
domain object to hold attributes and methods to be used on the StateMachine
definition.
Hint
Domain models are registered as Observers, so you can have the same level of functionalities provided to the built-in StateMachine, such as implementing all Actions and Guards on your domain model and keeping only the definition of States and Transitions on the StateMachine.