Java设计模式-模板设计模式
/**
* 模板设计模式:定义一个操作算法中的框架
* @author lin
*
*/
public class Cook{
public void lunch() {
buying();
washing();
cooking();
eating();
}
public void buying() {
System.out.println("买菜");
}
public void washing() {
System.out.println("洗菜");
}
public void cooking() {
System.out.println("炒菜");
}
public void eating() {
System.out.println("吃菜");
}
}
class Test {
public static void main(String[] args) {
Cook cook = new Cook();
cook.lunch();
}
}
控制台输出: 买菜 洗菜 炒菜 吃菜

浙公网安备 33010602011771号