• <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>

            C++研究

            C++細節深度探索及軟件工程

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              37 隨筆 :: 0 文章 :: 74 評論 :: 0 Trackbacks

             

            The Gof has 23 design patterns , but in most of  the design books , the E.G is written in Java , So  from now on , I will write about 23 articles to implement them using C++ , the design pattern itself is discussible , so welcome everyone to give his excelent idea to me , My QQ: 286259397 And My MSN : cxl82116@msn.com.
            Welcome every one to express his ideas!

             


            This is the First Arcticle: ABSTRACT FACTORY

            Here the theory goes:

            /*The theory basis :
              While using abstract factory , the  situation will be almost like this:
              we can create a real product from the abstract product , there are many series of product ,
              and the all have the similar property and operations , the operations can be different inner,
              but all the same interface outer;
              What's need?
              An abstract factory , and many real factory derived from this factory create real products
              An abstract product , any many real product derived from this proudct ;
              An abstract Interface , and many real Interface  that realize the interface
            */

            Here the code goes:

             

              1/********************************************************************
              2created: 2007/04/18
              3created: 18:4:2007   0:42
              4filename:  C:\testvc6\TestStll\TestStll.cpp
              5file path: C:\testvc6\TestStll
              6file base: TestStll
              7file ext: cpp
              8author:  Chang xinglong(King.C)
              9
             10  purpose: Abstract Factory
             11*********************************************************************/

             12
             13
             14#include <iostream>
             15using namespace std;
             16
             17//the abstract implementation
             18class AbsProductImp 
             19{
             20public:
             21    virtual void DrawProductShape()=0;
             22}
            ;
             23//the abstract factory
             24class AbsFactory
             25{
             26public:
             27    virtual AbsProductImp * CreateAProductImp()=0;  //Create a real implement
             28}
            ;
             29
             30//the abstract product 
             31class AbsProduct
             32{
             33public:
             34    //virtual void DrawProductShape();
             35protected:
             36    AbsProductImp * _imp;  //implement pointer , it's decide which implement be execute
             37    AbsFactory * _Fac;// this pointer will point to the real factory 
             38    
             39}
            ;
             40// Derived begain [4/18/2007 Chang Xinglong(King.C)]
             41
             42class AProductImp :public AbsProductImp //the real a product
             43{
             44public:
             45    void DrawProductShape()
             46    {
             47        cout<<"A product is describing itselfA is implement complete "<<endl;
             48    }

             49    
             50}
            ;
             51class BProductImp :public AbsProductImp  //the real a product
             52{
             53public:
             54    virtual void DrawProductShape()
             55    {
             56        cout<<"B product is describing itselfB is implement complete "<<endl;
             57    }

             58    
             59}
            ;
             60// Derived the Factory [4/18/2007 Chang Xinglong(King.C)]
             61class AFactory :public AbsFactory//The factory that create A
             62{
             63public:
             64    virtual AbsProductImp * CreateAProductImp()
             65    {
             66        return new AProductImp;
             67    }

             68    
             69}
            ;
             70
             71class BFactory : public AbsFactory
             72{
             73public:
             74    virtual AbsProductImp * CreateAProductImp()
             75    {
             76        return new BProductImp;
             77    }

             78    
             79}
            ;
             80
             81class AProduct :public AbsProduct
             82{
             83public:
             84    AProduct()
             85    {
             86        _Fac=new AFactory; // specific the AFactory to create A
             87        _imp=_Fac->CreateAProductImp(); // polymorphism , select the product implement
             88        _imp->DrawProductShape(); //construct it self
             89    }

             90}
            ;
             91
             92class BProduct :public AbsProduct
             93{
             94public:
             95    BProduct()
             96    {
             97        _Fac=new BFactory; // specific the BFactory to create B
             98        _imp=_Fac->CreateAProductImp(); // polymorphism , select the product implement
             99        _imp->DrawProductShape(); //construct it self
            100    }

            101}
            ;
            102// Derived the products [4/18/2007 Administrator]
            103int main(int argc, char* argv[])
            104{
            105    AProduct _a;  //Create An AProduct
            106    BProduct _b;  //Create A  BProduct
            107    return 1;
            108}

            109
            110
            111
            112
            posted on 2007-04-18 02:26 常興龍 閱讀(984) 評論(2)  編輯 收藏 引用 所屬分類: Design Patterns & Engeering

            評論

            # re: Implement "GOF's Abstract Factory" Using C++(Series of Gof patterns using C++ 1st article) 2007-04-18 11:25 abware
            GOF里的代碼就是C++的啊。  回復  更多評論
              

            # re: Implement "GOF's Abstract Factory" Using C++(Series of Gof patterns using C++ 1st article) 2007-04-18 17:38 夢在天涯
            雖然gof里有C++的實現,但是希望堅持寫下去,最好用平常我們生活中的實例,更淺顯易懂!
            可以加入msn C++高級編程群:group2041@xiaoi.com  回復  更多評論
              

            > hi的博客
            久久精品国产99国产精品| 99蜜桃臀久久久欧美精品网站| 亚洲&#228;v永久无码精品天堂久久 | 青青热久久国产久精品 | 精品久久久久久99人妻| 无码专区久久综合久中文字幕| 亚洲精品国产综合久久一线| 久久天天躁狠狠躁夜夜2020老熟妇| 777久久精品一区二区三区无码| 久久综合精品国产二区无码| 久久精品中文无码资源站| 久久亚洲精品无码AV红樱桃| 精品少妇人妻av无码久久| 国内精品伊人久久久久AV影院| 国产99精品久久| 国产 亚洲 欧美 另类 久久| 久久久久一级精品亚洲国产成人综合AV区 | 国产激情久久久久影院| 国产日韩久久免费影院| 久久人人爽人人爽人人片AV麻豆 | 中文成人无码精品久久久不卡| 久久久久久无码国产精品中文字幕| 久久久综合香蕉尹人综合网| 狠狠色丁香久久婷婷综合_中 | 久久精品无码一区二区三区日韩 | 日本人妻丰满熟妇久久久久久| 婷婷五月深深久久精品| 久久精品国产91久久麻豆自制| 久久久久国产一区二区三区| 亚洲伊人久久综合中文成人网| 人妻无码αv中文字幕久久琪琪布| 亚洲一本综合久久| 久久久久久精品久久久久| 国内精品久久久久影院日本| 人妻少妇精品久久| 99久久精品日本一区二区免费| 久久天天躁狠狠躁夜夜av浪潮| 久久99精品久久久久久久不卡 | 久久午夜羞羞影院免费观看| 精品久久久久国产免费| 亚洲AV无码久久精品色欲|