OO Programming with Java


Templates

A sample use is then:

public static void main(String[] args) {
  GOrder<String> o = new GOrder();
  o.add("Chicken"); o.add("French Fries"); o.add("Salad");
  System.out.println(o);
}

As another example, orders can now be detailled without changing structure:

public class DemoItem {
  public static void main(String args[]) {
    Item chicken  = new Item(Kind.Dish,   "Chicken",    15.0);
    Item fries    = new Item(Kind.Dish,   "French Fries",5.0);
    Item tiramisu = new Item(Kind.Dessert,"Tiramisu",    8.0);
    GOrder<Item> order = new GOrder<Item>();
    order.add(chicken); order.add(fries); order.add(tiramisu);
    System.out.println(order);
  }
}

go further


4