Keeping the state machine outside of the model has a couple of advantages.
- Cleans up the model: large state machines will definitely cause your class to go over 100 lines, which is bad for readability and maintainability.
- Explicit: It more explicit a state machine is being called. Calling
reservation.state.accepted?makes it instantly clear that we’re dealing with a ‘magic’ Workflow-method here instead of a boolean attribute in the
- Prevents collisions: state machines have the habit of tacking on many methods for each state and event (GoBoat’s state machine adds about 60).