黑马程序员技术交流社区
标题:
模版方法设计模式是不是23种设计模式之一
[打印本页]
作者:
吕晓阳
时间:
2015-4-16 14:37
标题:
模版方法设计模式是不是23种设计模式之一
模版方法设计模式代码示例:获取一段程序的运行时间
abstract class GetTime
{
public final void getTime()
{
long start = System.currentTimeMillis();
runcode();
long end = System.currentTimeMillis();
System.out.println("毫秒:"+(end-start));
}
public abstract void runcode();
}
class SubTime extends GetTime
{
public void runcode()
{
for(int x=0; x<4000; x++)
{
System.out.print(x);
}
}
}
class TemplateDemo
{
public static void main(String[] args)
{
SubTime gt = new SubTime();
gt.getTime();
}
}
复制代码
作者:
吕晓阳
时间:
2015-4-16 14:39
是不是呢?
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2