# "Coffee Machine" O-O design exercise

## create an O-O class diagram for this application

Application: You and I are contractors who just won a bid to design a custom coffee vending machine for the employees of Acme Fijet Works to use. Arnold, the owner of Acme Fijet Works, like the common software designer, eschews standard solutions. He wants his own, custom design. He is, however, a cheapskate. Arnold tells us he wants a simple machine. All he wants is a machine that serves coffee for 35 cents, with or without sugar and creamer. That's all. He expects us to be able to put this little machine together quickly and for little cost. We get together and decide there will be a coin slot and coin return, coin return button, and four other buttons: black, white, black with sugar, and white with sugar.

Now design the machine using objects. What are the components, what are their responsibilities, how do they work together to deliver the simple service: give coffee for 35 cents? Which component knows the price of the drink? Which component knows how to make the drink?

Test your design against Kim's test scenarios:
• Kim puts in a quarter and then selects a coffee.
• Kim puts two quarters in and then selects a coffee.
• Kim puts in a quarter, then pushes the coin return lever.
• Kim puts in two quarters, then walks away from the machine and forgets to come back.
• Kim buys two coffees, white with sugar. The sugar dispenser runs out of sugar after the first.
Requirement changes:
• After five machines are installed and have been operating for a while, Arnold comes along and says, "I would like to add bouillon, at twenty-five cents. Change the design." We add one more button for bouillon, and one more container for bouillon powder. How else do you change your design?

• People are starting to buy Starbucks lattes instead of Arnold's coffees. So Arnold wants the machine modified just slightly, so that he can create a "drink of the week." He wants to be able to add new drinks and change prices any time, to match his competition. He wants to be able to add espresso, cappuccino, hot chocolate, latte, choco-latte, steamed milk — in short, anything he can mix together.
Can your design easily handle these changes?