模版模式就是定义一个算法的骨架,而将具体的算法延迟到子类中来
实现:
package demo1; /* java设计模式之 模板模式 */ public class Test{ public static void main(String[] args) { System.out.println(new Test1().getScheduleTime()); } } abstract class TimeTemplate { public long getScheduleTime(){ long start = System.currentTimeMillis(); code(); long end = System.currentTimeMillis(); long delta = end - start; return delta; } public abstract void code(); } class Test1 extends TimeTemplate{ public void code(){ for (int i = 0; i < 100000; i++) System.out.println("我喜欢林志玲"); }; }