軟件藝術思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           
          適配器模式
          適配器模式可以把兩個不相關的類組裝在一起使用。實際上是繼承和組合的綜合運用。
          讓我們來看一個例子:
          public interface Itable{
          public void say(String str);
          }
          public interface Ichair{
          public void say(String str);
          }
          public class Table implements? Itable{
            public void say(String str){
              System.out.println(" i am a table :"+str);
            }
          }
          public class Chair implements Ichair{
            public void say(String str){
              System.out.println(" i am a chair :"+str);
            }
          }

          public class AdapterFitment? extends Table{
          private Ichair c;
          ? public AdapterFitment(Ichair c){
          ? this.c=c;
          }
          public void insert(String str){c.say(str);}
          }

          然后呢,這個組合家具就即能當桌子用又能當椅子用了。
          posted on 2006-07-25 18:21 智者無疆 閱讀(439) 評論(2)  編輯  收藏 所屬分類: software project
          評論:
          • # re: java模式學習(3)  anonymous Posted @ 2006-12-05 17:14
            adpater的目的是將一種物件視為另一種物件,文中最后部分的解釋偏離了模式本身。  回復  更多評論   

          • # re: java模式學習(3)  anonymous Posted @ 2006-12-05 17:20
            deal with chair as a table

            public class Adapter2Table implements ITable{

            private IChair chair;

            public Adapter2Table(IChair chair){
            this.chair = chair;
            }

            public void Say(String str){
            chair.Say(str);
            }
            }  回復  更多評論   

           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 安塞县| 合阳县| 昌邑市| 天门市| 昌平区| 潍坊市| 榆林市| 新宾| 威信县| 嘉祥县| 新河县| 津南区| 逊克县| 沂源县| 莱州市| 海伦市| 鄂伦春自治旗| 绥江县| 罗山县| 桂林市| 泗水县| 页游| 乌鲁木齐市| 黄浦区| 白银市| 元朗区| 临湘市| 时尚| 建瓯市| 方山县| 京山县| 河间市| 乐陵市| 阳新县| 行唐县| 锡林郭勒盟| 大宁县| 南阳市| 治县。| 眉山市| 吉隆县|