~learn.
lecture · 13:30 · 4 checkpoints · browser voice

Design a vending machine

The State pattern done properly: draw the states first, one class per state answering every event, the machine as a context holding data and an escrow, change made from the coins actually in the box (where greedy fails), one lock for many inputs, and follow-ups that are new states.

01 · Six rupees of change
LLD-07 · Design a Vending Machine

₹20 in, ₹14 biscuits, ₹6 to give back.

₹6 owed, from 5, 2, 2, 2

A customer puts a 20 rupee note into a vending machine for 14 rupee biscuits.