The Elements of Class Design

A scenario for vending machine architecture

a vending machine allows products to be purchased by inserting the correct amount of money into the machine. A user selects a product from a list of available products, adds coins to cover a given cost, and get the product delivered. A display indicates how much money has been entered. When a selection is made, the following disjoint outcomes are possible:

a) the product is delivered, and if the amount entered is larger than the price, the difference is refunded. The inventory is updated to indicate that there is one fewer item for this particular product.

b) If there are not enough coins in the machine to produce the proper change, the display must show an appropriate message, and no item is delivered.

c) The amount entered does not cover the price of the item.

d) The product is sold out.

In each case, an appropriate message is displayed.
The machine can be serviced by an authorized operator. When the machine is unlocked, the coin receptacle is emptied. The operator can restock any one of the bins of items, and the corresponding inventory count must be updated.
For internal accounting, the machine keeps track of the total amount of money it holds, both as a total, and per denomination (nickels, dimes, etc.).