// ConcreteClass - 具体类 // 茶 public class Tea extends CaffeineBeverage { public void brew() { System.out.println("Steeping the tea!"); } public void addCondiments() { System.out.println("Adding Lemon!"); } }
// 咖啡 public class Coffee extends CaffeineBeverage { public void brew() { System.out.println("Dripping Coffee through filter!"); } public void addCondiments() { System.out.println("Adding Sugar and Milk!"); } public void hook() { System.out.println("Please give me a spoon!"); } }
public class Test { public static void main(String[] args) { CaffeineBeverage tea = new Tea(); CaffeineBeverage coffee = new Coffee(); tea.prepareRecipe(); coffee.prepareRecipe(); } }