System.out.println("\nMaking tea...");
teaHook.prepareRecipe();
System.out.println("\nMaking coffee...");
coffeeWithHook.prepareRecipe();
}
}
package hook;
public class BeverageTestDrive {
public static void main(String[] args) {
TeaWithHook teaHook = new TeaWithHook();
CoffeeWithHook coffeeWithHook = new CoffeeWithHook();
System.out.println("\nMaking tea...");
teaHook.prepareRecipe();
System.out.println("\nMaking coffee...");
coffeeWithHook.prepareRecipe();
}
}
测试结果:
Making tea...
Boilng water
Steeping the tea
Pouring into cup
Would you like lemon with your tea (y/n)
y
Adding Lemon
Making coffee...
Boilng water
Dripping Coffee through filter
Pouring into cup
Would you like milk and sugar with your coffee (y/n)
y
Adding Sugar and Milk