Interpret state machines by using an interpreter. The machine should toggle between the inactive
and active
states:
- In the
inactive
state, when amousedown
event happens, go toactive
. - In the
active
state, when amouseup
event happens, go toinactive
.
- Use the same machine as Exercise 02.
- Use
interpret(...)
to create aservice
that interprets the machine. - Start the service with
service.start()
. - Use
service.send(...)
to send events to the running service.
- Send the raw event from the event handler to the service instead. Notice how it fits the event object shape!
- Practice stopping the service when you no longer need it with
service.stop()
(e.g., after 10 seconds or so).