My implementation of Guy Royse's Vending Machine Kata.
Vending machines are really just Finite State Machines and can be implemented in hardware. If the wikipedia article above is a bit too heavy, there's a great video from Computerphile, Computers without memory.
Being we're building a state machine, I suspect we'll make use of the state pattern.
The following display states exist:
- No Money (Insert Coin/Exact Change)
- Money (Current Value)
- Display Price
- Display Thank you!
- Sold Out
- The change making algorithm does find opitmal results, but the Exact Change Only algorithm does not.
- Move to the Greedy Algorithm to make it a more robust solution all around.
- I don't care for the fact that the abstract base
VendingMachineState
class has knowledge of its inheritors.- It was implemented this way to centralize logic that would have otherwise had to have been implemented in each of the child classes.
- Find a way to decouple it.
- There are several missing states. A few of the states have
if...then
logic that should really be represented as different states unto themselves.
Nothing special here. Just compile and run the tests.