
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6
The chef is represented as an interface IChef with two methods, one to cook a vegetarian dish and one to cook a meat dish, as shown in the table below.
interface IChef {
String cookVeggie(Vegetarian h, Integer n); }
String cookMeat(Carnivore h, Integer n); |
public class ChefWong implements IChef {
public static final ChefWong Singleton
= new ChefWong();
private ChefWong() {}
public String cookVeggie(
Vegetarian h, Integer n) {
return n + " portion(s) of " +
h.getCarrot() + ", " +
h.getSalt();
}
public String cookMeat(
Carnivore h, Integer n) {
return n + " portion(s) of " +
h.getMeat() + ", " +
h.getPepper();
}
} |
public class ChefZung implements IChef { public static final ChefZung Singleton = new ChefZung(); private ChefZung() {} public String cookVeggie( Vegetarian h, Integer n) { return n + " portion(s) of " + h.getCorn() + ", " + h.getSalt(); } public String cookMeat( Carnivore h, Integer n) { return n + " portion(s) of " + h.getChicken() + ", " + h.getPepper() + ", " + h.getSalt(); } } |
- 1523 reads