黑马程序员技术交流社区

标题: 模版方法设计模式是不是23种设计模式之一 [打印本页]

作者: 吕晓阳    时间: 2015-4-16 14:37
标题: 模版方法设计模式是不是23种设计模式之一
模版方法设计模式代码示例:获取一段程序的运行时间
  1. abstract class GetTime
  2. {
  3. public final void getTime()
  4.         {
  5.                 long start = System.currentTimeMillis();
  6.                 runcode();
  7.                 long end = System.currentTimeMillis();
  8.                 System.out.println("毫秒:"+(end-start));
  9.         }
  10.         public abstract void runcode();
  11. }
  12. class SubTime extends GetTime
  13. {
  14.         public void runcode()
  15.         {               
  16.                 for(int x=0; x<4000; x++)
  17.                 {
  18.                         System.out.print(x);
  19.                 }
  20.         }
  21. }
  22. class  TemplateDemo
  23. {
  24.         public static void main(String[] args)
  25.         {
  26.                 SubTime gt = new SubTime();
  27.                 gt.getTime();
  28.         }
  29. }
复制代码




作者: 吕晓阳    时间: 2015-4-16 14:39
是不是呢?




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2