• <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>
            隨筆-167  評論-8  文章-0  trackbacks-0
            The essence of the Abstract Factory Pattern is to "Provide an interface for creating families of related or dependent objects without specifying their concrete classes".
            class diagram
            uml diagram



             1 /* GUIFactory example */
             2  
             3 #include <iostream>
             4  
             5 class Button {
             6 public:
             7     virtual void paint() = 0;
             8     virtual ~Button() { }
             9 };
            10  
            11 class WinButton : public Button {
            12 public:
            13     void paint() {
            14         std::cout << "I'm a WinButton";
            15     }
            16 };
            17  
            18 class OSXButton : public Button {
            19 public:
            20     void paint() {
            21         std::cout << "I'm an OSXButton";
            22     }
            23 };
            24  
            25 class GUIFactory {
            26 public:
            27     virtual Button* createButton() = 0;
            28     virtual ~GUIFactory() { }
            29 };
            30  
            31 class WinFactory : public GUIFactory {
            32 public:
            33     Button* createButton() {
            34         return new WinButton();
            35     }
            36  
            37     ~WinFactory() { }
            38 };
            39  
            40 class OSXFactory : public GUIFactory {
            41 public:
            42     Button* createButton() {
            43         return new OSXButton();
            44     }
            45  
            46     ~OSXFactory() { }
            47 };
            48  
            49 class Application {
            50 public:
            51     Application(GUIFactory* factory) {
            52         Button* button = factory->createButton();
            53         button->paint();
            54         delete button;
            55         delete factory;
            56     }
            57 };
            58  
            59 GUIFactory* createOsSpecificFactory() {
            60     int sys;
            61     std::cout "\nEnter OS type (0: Windows, 1: MacOS X): ";
            62     std::cin >> sys;
            63  
            64     if (sys == 0) {
            65         return new WinFactory();
            66     } else {
            67         return new OSXFactory();
            68     }
            69 }
            70  
            71 int main() {
            72     Application application(createOsSpecificFactory());
            73 }
            74 
            posted on 2012-11-13 16:46 老馬驛站 閱讀(394) 評論(0)  編輯 收藏 引用 所屬分類: Design pattern
            中文字幕久久波多野结衣av| 久久婷婷国产剧情内射白浆| 国产亚洲色婷婷久久99精品| 精品一区二区久久久久久久网站| 国内精品免费久久影院| 久久天天躁狠狠躁夜夜不卡| 久久精品国产一区| 亚洲国产精品无码久久久秋霞2 | 91久久精品无码一区二区毛片| 欧美伊人久久大香线蕉综合69 | 精品人妻伦九区久久AAA片69 | 久久久久亚洲AV成人网人人网站 | 久久精品亚洲乱码伦伦中文| 日韩精品久久无码人妻中文字幕 | 精品久久久久久久久久久久久久久| 伊人久久大香线蕉无码麻豆| 久久福利片| 久久综合狠狠色综合伊人| 久久天天躁狠狠躁夜夜网站| 久久婷婷色香五月综合激情| 久久精品国产精品亚洲人人 | 99蜜桃臀久久久欧美精品网站| 国产综合成人久久大片91| 久久精品视频网| 久久99国产精品久久久| 99久久人妻无码精品系列 | 久久狠狠一本精品综合网| 精品久久一区二区| 国产精品九九九久久九九| 久久久久久久人妻无码中文字幕爆| 久久久久久久免费视频| 久久精品国产AV一区二区三区 | 色综合久久88色综合天天| 亚洲成人精品久久| 韩国三级中文字幕hd久久精品| 99久久国产免费福利| 久久99热这里只有精品国产| 久久久中文字幕日本| 波多野结衣久久一区二区| 久久亚洲私人国产精品vA | 婷婷综合久久中文字幕|