• <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 老馬驛站 閱讀(374) 評論(0)  編輯 收藏 引用 所屬分類: Design pattern
            亚洲欧美另类日本久久国产真实乱对白 | 99久久婷婷国产一区二区| 狠狠精品久久久无码中文字幕 | 国产精品久久久久免费a∨| 久久Av无码精品人妻系列| 狠狠色丁香久久婷婷综合_中| 国产91久久综合| 久久久精品日本一区二区三区| 精品久久久无码人妻中文字幕豆芽| 午夜欧美精品久久久久久久| 色婷婷狠狠久久综合五月| 色综合久久久久综合99| 大蕉久久伊人中文字幕| 国内精品伊人久久久久影院对白| 久久精品一区二区国产| 久久国产视屏| 欧美色综合久久久久久| 一本久久a久久精品亚洲| 狠狠色丁香久久婷婷综合图片| 一本色道久久HEZYO无码| 亚洲人成伊人成综合网久久久| 久久精品国产亚洲AV无码麻豆| 人妻丰满AV无码久久不卡| 欧美精品一区二区精品久久| 久久综合欧美成人| 国产精品久久久久蜜芽| 久久成人国产精品免费软件| 成人免费网站久久久| 国产成人精品久久综合| 狠狠色丁香婷婷久久综合五月| 久久综合亚洲色HEZYO社区| 久久青草国产手机看片福利盒子| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 亚洲国产精品久久久久| 亚洲国产精品久久久久婷婷软件| 香蕉99久久国产综合精品宅男自 | 久久综合视频网| 91精品国产综合久久精品| 亚洲午夜精品久久久久久app| 无码国内精品久久人妻蜜桃| 久久久黄片|