• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 183,  comments - 10,  trackbacks - 0

            適配器模式(Adapter):將一個類的接口轉換成客戶希望的另外一個接口。Adapter 模式使得原本由于接口不兼容而不能在一起工作的那些類可以一起工作。

            結構型
            ·類
            ·對象

            UML 類圖:


            代碼實現 C++:
              1 #include <iostream>
              2 #include <string>
              3 using namespace std;
              4 
              5 class Player
              6 {
              7 protected:
              8     string name;
              9 public:
             10     Player(const string& s = "") : name(s) {}
             11     virtual void Attack()  = 0;
             12     virtual void Defense() = 0;
             13 };
             14 
             15 class Forwards : public Player
             16 {
             17 public:
             18     Forwards(const string& s = "") : Player(s) {}
             19     virtual void Attack()
             20     {
             21         cout << "前鋒 " << name << " 進攻!" << endl;
             22     }
             23     virtual void Defense()
             24     {
             25         cout << "前鋒 " << name << " 防守!" << endl;
             26     }
             27 };
             28 
             29 class Center : public Player
             30 {
             31 public:
             32     Center(const string& s = "") : Player(s) {}
             33     virtual void Attack()
             34     {
             35         cout << "中鋒 " << name << " 進攻!" << endl;
             36     }
             37     virtual void Defense()
             38     {
             39         cout << "中鋒 " << name << " 防守!" << endl;
             40     }
             41 };
             42 
             43 class Guards : public Player
             44 {
             45 public:
             46     Guards(const string& s) : Player(s) {}
             47     virtual void Attack()
             48     {
             49         cout << "后衛 " << name << " 進攻!" << endl;
             50     }
             51     virtual void Defense()
             52     {
             53         cout << "后衛 " << name << " 防守!" << endl;
             54     }
             55 };
             56 
             57 class ForeignCenters
             58 {
             59 private:
             60     string name;
             61 public:
             62     ForeignCenters(const string& s = "") : name(s) {}
             63     void ForeignAttack()
             64     {
             65         cout << "外籍中鋒 " << name << " 進攻!" << endl;
             66     }
             67     void ForeignDefense()
             68     {
             69         cout << "外籍中鋒 " << name << " 防守!" << endl;
             70     }
             71 };
             72 
             73 class Translators : public Player
             74 {
             75 private:
             76     ForeignCenters* fc;
             77 public:
             78     Translators(const string& s = ""const string& f = "") : Player(s), fc(new ForeignCenters(f)) {}
             79     ~Translators()
             80     {
             81         delete fc;
             82     }
             83     virtual void Attack()
             84     {
             85         fc->ForeignAttack();
             86     }
             87     virtual void Defense()
             88     {
             89         fc->ForeignDefense();
             90     }
             91 };
             92 
             93 int main()
             94 {
             95     Player* b = new Forwards("巴蒂爾");
             96     b->Attack();
             97     b->Defense();
             98 
             99     Player* m = new Guards("麥克格雷迪");
            100     m->Attack();
            101     m->Defense();
            102 
            103     Player* y = new Translators("翻譯者""姚明");
            104     y->Attack();
            105     y->Defense();
            106 
            107     return 0;
            108 }
            posted on 2011-04-28 14:31 unixfy 閱讀(123) 評論(0)  編輯 收藏 引用
            99久久国产综合精品成人影院| 久久国产精品免费一区| 亚洲精品乱码久久久久久按摩 | 麻豆亚洲AV永久无码精品久久| 99久久久精品免费观看国产| 久久国产精品二国产精品| 77777亚洲午夜久久多喷| 国产日韩欧美久久| 色婷婷综合久久久久中文一区二区| 99国内精品久久久久久久| 久久人人爽人人爽人人片av高请| 久久无码国产| 国产A级毛片久久久精品毛片| 中文精品久久久久人妻不卡| 久久久久无码精品| 国产精品日韩深夜福利久久| 精品午夜久久福利大片| 久久亚洲中文字幕精品有坂深雪 | 久久婷婷色综合一区二区| 国产三级精品久久| 国产精品美女久久久| 亚洲AV无码一区东京热久久| 久久精品国产亚洲AV忘忧草18| 久久午夜综合久久| 久久久黄片| 四虎国产精品成人免费久久| 久久一区二区三区免费| 国产成人AV综合久久| 国产毛片久久久久久国产毛片| 一级做a爰片久久毛片16| 91精品国产高清久久久久久国产嫩草| 久久国产高潮流白浆免费观看| 久久亚洲精品人成综合网| 欧美噜噜久久久XXX| …久久精品99久久香蕉国产| 97久久精品国产精品青草| 四虎国产永久免费久久| 久久久久亚洲AV无码专区桃色| 久久五月精品中文字幕| 一本色道久久综合亚洲精品| 久久亚洲精品成人av无码网站|