Back to problems

Implement a Vending Machine

Object-Oriented Programming · Ziphq · Medium

Vending Machine — Object-Oriented Design with Change-Making Approach 1: Domain Model + Greedy Change Dispensing A vending machine is really a small state machine wrapped around a cash drawer. Three ideas carry the design: Products own their stock. A Product holds its id, its price in cents, and how many units remain. Selling a unit is a method on the product, so inventory can never drift out of sync with a purchase. The machine owns the transaction. A balance field…

Checking your access…