/* 定义功能,获取程序运行的时间。 在指定程序运行前记录一个时间。 在运行后记录一个时间,在相减 就哦了。 模版方法设计模式: 解决问题:当功能中一部分确定,一部分不确定,确定的部分还在使用不确定的部分, 就将不确定的部分暴露出去由子类去实现。 */ abstract class GetTime { public final void getTime() { long start = System.currentTimeMillis(); code(); long end = System.currentTimeMillis(); System.out.println("毫秒是:"+(end-start)); } public abstract void code(); } class Sub extends GetTime { public void code() { for(int x=0; x<10000; x++) { System.out.print("a"); } } } class TemplateDemo { public static void main(String[] args) { //GetTime gt = new GetTime(); //gt.getTime(); Sub s = new Sub(); s.getTime(); } }
模板设计模式
原创
©著作权归作者所有:来自51CTO博客作者初级菜鸟牛的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:date timestamp
下一篇:不同数据结构的比较原理
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
设计模式-模板方法模式
设计模式,模板方法模式,C#设计模式,.net设计模式
设计模式 模板 方法模式