Monday, April 14, 2014

Design a vending machine like coffee vending machine

Broadly, think about what objects are involved in a vending machine:
  • VendingMachine - possibly an abstract class
  • DrinkMachine, SnackMachine, and classes extending VendingMachine
  • VendingProduct - an abstract class?
  • Drink, other classes extending VendingProduct
  • Coke, other classes extending Drink
  • &c, &c.
But I'm sure you can figure that out pretty easily. The nuts and bolts of the machine will take place in some kind of utility class, with methods to accept bills and coins, calculate change, etc.

Also, Getting the coffee will be got from the factory:
public class CoffeeVendingMachine extends VendingMachine{
   private Milk milk;
   private Sugar sugar;
   public Coffee getCoffee(CoffeeTypeEnum coffeeType){
   private void prepareCoffee(CoffeeTypeEnum coffeeType{
      //internal process for coffee making

Note that prepareCoffee is private method, as users don't want to know how coffee is made.

Here is the basic class diagram for vending machine(borrowed from programsfromca):
 Note that VendingMachine composes SelectionPanel, Controller, Product and so on.



Post a Comment