隨筆 - 117  文章 - 72  trackbacks - 0

          聲明:原創(chuàng)作品(標有[原]字樣)轉(zhuǎn)載時請注明出處,謝謝。

          常用鏈接

          常用設(shè)置
          常用軟件
          常用命令
           

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 156395
          • 排名 - 390

          最新評論

          [關(guān)鍵字]:java,design pattern,設(shè)計模式,《Java與模式》學(xué)習(xí),template method pattern,模板方法模式
          [環(huán)境]:StarUML5.0 + JDK6
          [作者]:Winty (wintys@gmail.com) http://www.aygfsteel.com/wintys/
          [正文]:


          package pattern.template;
          /**
           * 模板方法模式:Template Method Pattern
           * @version 2009-6-15
           * @author Winty(wintys@gmail.com)
           */
          public class TemplateMethodTest{
              public static void main(String[] args){
                  AbstractClass ac = new ConcreteClass();
                  ac.theTemplateMethod();
              }
          }

          /**
           * 抽象模板角色,在此定義模板方法
           */
          abstract class AbstractClass{
              public void theTemplateMethod(){
                  operation1();
                  operation2();
                  operation3();
                  doHookOperation();
              }

              protected abstract void operation1();
              protected abstract void operation2();

              public final void operation3(){
                  System.out.println("operation3");
              }

              public void doHookOperation(){
                  //空方法
              }
          }

          /**
           * 具體模板角色
           */
          class ConcreteClass extends AbstractClass{
              protected void operation1(){
                  System.out.println("operation1");
              }

              protected void operation2(){
                  System.out.println("operation2");
              }
          }


          posted on 2009-06-15 17:05 天堂露珠 閱讀(1330) 評論(0)  編輯  收藏 所屬分類: Pattern
          主站蜘蛛池模板: 马尔康县| 广西| 遂昌县| 萨迦县| 岳阳县| 务川| 来安县| 五指山市| 东港市| 五大连池市| 通化市| 南靖县| 上林县| 隆安县| 沙洋县| 秭归县| 桂林市| 临湘市| 乐安县| 高碑店市| 北票市| 徐闻县| 二连浩特市| 松潘县| 德惠市| 西昌市| 延寿县| 洛南县| 郧西县| 视频| 惠来县| 出国| 德化县| 久治县| 新绛县| 蓬莱市| 台前县| 左贡县| 兴文县| 旬阳县| 达日县|