设计模式学习--模板方法模式(Tamplate Pattern) (三)

2014-11-24 10:31:15 · 作者: · 浏览: 3
Hook coffeeWithHook = new CoffeeWithHook();

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