本站不再更新,歡迎光臨 java開發(fā)技術網(wǎng)
          隨筆-230  評論-230  文章-8  trackbacks-0

          定義:
          ???????? 定義一個算法中的骨架,將一些步驟的執(zhí)行延期到子類,其實JAVA中的操象類就是一個Template模式,因些使用得很普遍,很容易理解。如:
          package com.pdw.pattern;

          abstract class Benchmark{
          ?public abstract void benchmark();
          ?
          ?/**
          ? * 重復執(zhí)行的次數(shù)
          ? * @param count
          ? * @return
          ? */
          ?public final long repeat(int count){
          ??long startTime;
          ??if(count<0){
          ???return 0;
          ??}else{
          ???startTime=System.currentTimeMillis();
          ???for(int i=0;i<count;i++){
          ????benchmark();
          ???}
          ??}
          ??long stopTime=System.currentTimeMillis();
          ??return stopTime-startTime;
          ??
          ?}
          }
          class MethodBenchmark extends Benchmark{

          ?public void benchmark() {
          ??for(int i=0;i<200000;i++){
          ???System.out.println("i="+i);
          ??}
          ?}
          ?
          }

          public class TemplateImpl {
          ?/**
          ? * @param args
          ? */
          ?public static void main(String[] args) {
          ??Benchmark operation=new MethodBenchmark();
          ??long d=operation.repeat(1);
          ??System.out.println("執(zhí)行一次所需要用的時間:"+d);
          ?}

          }

          posted on 2006-07-09 22:58 有貓相伴的日子 閱讀(307) 評論(0)  編輯  收藏 所屬分類: Patterns
          本站不再更新,歡迎光臨 java開發(fā)技術網(wǎng)
          主站蜘蛛池模板: 阿坝| 河间市| 绥芬河市| 南川市| 游戏| 玛多县| 彭泽县| 彭水| 婺源县| 温泉县| 武平县| 罗田县| 平远县| 吴川市| 榆中县| 铁岭市| 万荣县| 黔南| 名山县| 莱芜市| 泗水县| 南召县| 诸暨市| 衡水市| 屯昌县| 太仆寺旗| 吴堡县| 高要市| 裕民县| 萍乡市| 都江堰市| 武宁县| 康定县| 花莲市| 拜泉县| 蕲春县| 田东县| 长武县| 卢龙县| 勃利县| 仙居县|