Table, or a class per state? Look at the cell
transcript
Two ways to build a state machine. A class per state, or a table. People argue about this. Which one? Look at what a cell contains.
In the order, the cell holds data. Which events are allowed. A label. A refund percent. In the vending machine, the cell holds code. Check the slot. Check the balance. Work out the change.
If the cells hold data, a table is enough. Five lines, in one place. Easy to read and test. If they hold code, use a class per state. Each answer stays next to its state. Sixteen answers, in four classes. When unsure, start with the table. Move to classes when a cell wants more.
Our order has five states. With four events, that's 20 pairs. Only five are legal. Both designs print exactly the same grid, in all four languages.
Data in the cell? A table. Simple. Code in the cell? Classes.
Full breakdown in the lecture.