JAVA的模版方法模式

 模版方法设计模式:在定义功能时,功能的一部分是确定是,但是有一部分是不确定的,而确定的部分在使用不确定的部分,这时就将不确定的部分暴露出去,由该类的子类去完成

 

 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 
13 class SubTime extends GetTime
14 {
15     public void runcode()
16     {
17         for(int x = 0;x < 4000; x++)
18         {
19              System.out.println(x);
20         }
21     }
22 }
23 
24 class TemplateDemo
25 {
26     public static void main(String[] args)
27     {
28         //GetTime gt = new GetTime();
29         //gt.getTime();
30         SubTime gt = new SubTime();
31         gt.getTime();
32     }
33 }

 

posted on 2017-06-07 21:57 零EVA 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/hepengke/p/6959279.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值