抽象类模板设计模式

 1 package com.Chapter01.Abstract;
 2 
 3 abstract public class template { //抽象类 摸版设计
 4     public abstract void job();//抽象方法;
 5     public void calculate(){
 6         //开始时间
 7         long start = System.currentTimeMillis();
 8         // 结束时间
 9         job();
10         long end = System.currentTimeMillis();
11         System.out.println("执行所需时间"+(end-start));
12     }
13 }
 1 package com.Chapter01.Abstract;
 2 
 3 public class Abstract03 {
 4 
 5 }
 6  class Soul extends template{ //继承template类
 7     //计算任务
 8     //1+.....+10000
 9 
10      //工作方法:
11     public void job(){
12         long sum= 0;
13         for (long i = 1; i <= 60000; i++) {
14             sum+=i;
15         }
16     }
17 }
1 package com.Chapter01.Abstract;
2 //用于测试
3 public class AbstractTest {
4     public static void main(String[] args) {
5         Soul soul = new Soul();
6         soul.calculate();
7     }
8 }

 

posted @ 2022-06-07 10:56  捞月亮的渔夫  阅读(35)  评论(0)    收藏  举报