Monday, April 14, 2014

Design a vending machine like coffee vending machine

This updated information has been further expanded upon on my new website. You can find the updated details here: https://k5kc.com/cs/ood/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){
      prepareCoffee(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.

References

2 comments:

  1. How is the above UML going to look like when coded using CLIPS?

    ReplyDelete
    Replies
    1. hey, I havent coded in CLIPS...(apologies for such a late response). I have updated the content here: https://k5kc.com/cs/ood/design-a-vending-machine-like-coffee-vending-machine/ and I am using mermaid to draw the diagram.

      Delete