//模板方法:步驟提前設計好,用的時候只需要改步驟內容 public class TemplateDemo { public static void main(String[] args) { // TODO Auto-generated method stub teacher DBtea = new DBTeacher(); teacher Ctea = new CTeacher(); DBtea.work(); Ctea.work(); } } abstract class teacher{ public void prepared() { System.out.println("整理資料"); System.out.println("開啟投影儀"); } public abstract void teaching();//抽象方法,子類需重寫 public void end() { System.out.println("關閉投影儀"); System.out.println("帶走資料"); } //老師的工作流程/模板方法 public void work() { prepared();//課前準備,每個老師都一樣 teaching();//講課 end();//結束,每個老師都一樣 } } class DBTeacher extends teacher{ public void teaching() { System.out.println("開啟oracle"); System.out.println("寫pl-sql"); } } class CTeacher extends teacher{ public void teaching() { System.out.println("開啟VM"); System.out.println("寫C指令"); } }