package com.study.handcode.设计模式.行为型模式;import java.io.InputStream;public class 二十三种设计模式之模版方法模式 {public static void main(String[] args) {StirFly flyEgg = new FlyEgg();flyEgg.cookprocess();StirFly pork = new SweetSourPork();pork.cookprocess();}static abstract class StirFly{public final void cookprocess(){ System.out.println("===炒菜步骤===");this.pourOil();this.heatOil();this.pourVegetable();this.addOther();this.fly();System.out.println("===炒菜结束===");}private void fly() {System.out.println("5、开始翻炒");}public abstract void addOther();public abstract void pourVegetable();private void heatOil() {System.out.println("2、热油");}private void pourOil() {System.out.println("1、开始倒油");}}static class FlyEgg extends StirFly{@Overridepublic void addOther() {System.out.println("4、加入盐巴");}@Overridepublic void pourVegetable() {System.out.println("加入鸡蛋");}}static class SweetSourPork extends StirFly{@Overridepublic void addOther() {System.out.println("4、加入糖");}@Overridepublic void pourVegetable() {System.out.println("3、加入鸡肉");}}
}