• <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++細(xì)節(jié)深度探索及軟件工程

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

            This is the 4Th Arcticle: Builder PATTERN

            Separates the construction of a complex object from its representation so that the same construction process can create different representations.  --Gof

             The builder pattern can separate the representation and construction easily , while you building a big-pang object , and some of the object itself  is

            diversified and  could be build separately , considering this pattern.

            Participants:

          1. Builder.
            • specifies an abstract interface for creating parts of a Product object
          2. ConcreteBuilder.
            • constructs and assembles parts of the product by implementing the Builder interface
            • defines and keeps track of the representation it creates
            • provides an interface for retrieving the product
          3. Director.
            • constructs an object using the Builder interface
          4. Product.
            • represents the complex object under construction. ConcreteBuilder builds the product's internal representation and defines the process by which it's assembled
            • includes classes that define the constituent parts, including interfaces for assembling the parts into the final result 


          5.  The diagram goes here:


            Code is the most clearly lauguage for out programmers , so  I will use code to expree this pattern clearly as follows:

              1
              2/* this is the diversfied part*/
              3
              4//abstract
              5class House
              6{
              7
              8}
            ;
              9//abstract
             10class Door
             11{
             12
             13}
            ;
             14
             15//concrete, transformation
             16class FeDoor: public Door
             17{
             18
             19}
            ;
             20//concreate, transformation
             21class WoodDoor: public Door
             22{
             23
             24}
            ;
             25
             26//abstract
             27class Window
             28{
             29
             30}
            ;
             31//concreate , transformation
             32class FeWindow :public Window
             33{
             34
             35}
            ;
             36//concreate, transformation
             37class WoodWindow :public Window
             38{
             39
             40}
            ;
             41
             42/*this is the builder the stable part*/
             43class Builder
             44{
             45
             46protected:
             47    //build every part here
             48    virtual  void BuildeDoor();
             49    virtual  void BuildeWindow();
             50    virtual void  BuildFloor();
             51    //to get the result
             52public:
             53    virtual void GetHouse();
             54    
             55}

             56
             57class FeHouseBuilder :public Builder
             58{
             59public:
             60    GetHouse()
             61    {
             62        return /*window + door */
             63    }

             64protected:
             65    void BuildeDoor()
             66    {
             67       
             68        aDoor=new FeDoor();
             69    }

             70    void BuildWindow()
             71    {
             72        aRedWindow=new FeWindow();
             73    }

             74private:
             75    Window aWindow;
             76    Door aDoor;
             77
             78}

             79
             80class WoodHouseBuilder :public Builder
             81{
             82public:
             83    House GetHouse()
             84    {
             85        return /*window + door */
             86    }

             87protected:
             88    void BuildeDoor()
             89    {
             90       
             91        aDoor=new WoodDoor(); //can change 
             92    }

             93    void BuildWindow()
             94    {
             95        aRedWindow=new WoodWindow(); //can change too
             96    }

             97private:
             98    Window aWindow;
             99    Door aDoor;
            100
            101}

            102
            103class Director
            104{
            105public:
            106    //Create a house that has two doors and a window , this is the creator part , It's usually Stable too
            107    static House Construct(Builder builder)
            108    {
            109       builder.BuildeDoor();
            110       builder.BuildeDoor();
            111       builder.BuildeWindow();
            112
            113       return builder.GetHouse();
            114    }

            115
            116}
            ;
            117
            118//client
            119int main(int argc , char * argv[])
            120{
            121   //read the config file 
            122   //build a fe House with two doors and a window
            123    Director::Construct(new FeHouseBuilder());
            124   //builder a wood house with two doors and a window 
            125    Director::Construct(new WoodHouseBuilder());
            126
            127    /*two doors and a window is stable , and  the house 's architecture is stable too ,but the material*/
            128
            129}


             1-40  is the diversification , the house's architecture is stable , you create a mixed house easily if you like ,  simply add a class called mixedhouseBuidler and use the right part(like the FeDoor  and WoodDoor ) to create the mixed house ,and use the mixedHouseBuilder to builde you work.

            simple and practible!
            posted on 2007-06-02 17:34 常興龍 閱讀(1006) 評論(4)  編輯 收藏 引用 所屬分類: Design Patterns & Engeering

            評論

            # re: Implement "GOF's Builder pattern" Using C++(Series of Gof patterns using C++ 4th article) 2007-06-02 20:28 萬星星
            用設(shè)計(jì)模式來設(shè)計(jì)一個真實(shí)的系統(tǒng),把理想的東西和現(xiàn)實(shí)的世界結(jié)合起來,或許可以學(xué)到更多,成長更快,理解的更加深刻。
            一個系統(tǒng)用上4、5個模式應(yīng)該就比較成功了。  回復(fù)  更多評論
              

            # re: Implement "GOF's Builder pattern" Using C++(Series of Gof patterns using C++ 4th article) 2007-06-03 14:12 常興龍
            設(shè)計(jì)模式,相似的代碼很可能是不同的模式,不同的代碼很可能是相同的模式思想。萬變不離其蹤,這里只給了一種自我思考的例子。放入工程中別人很難看清楚是什么,因而不能發(fā)表其也許更好的見解。多謝評論!  回復(fù)  更多評論
              

            # re: Implement "GOF's Builder pattern" Using C++(Series of Gof patterns using C++ 4th article) 2007-06-04 13:58 picasa
            誰能翻一下  回復(fù)  更多評論
              

            # re: Implement "GOF's Builder pattern" Using C++(Series of Gof patterns using C++ 4th article) 2007-09-28 20:12 馬承志
            主人的想法非常好,當(dāng)然如果能在現(xiàn)實(shí)的項(xiàng)目中使用模式解決問題才是根本.不過通過C++完成所有的模式也是一種實(shí)踐.可以加深我們的理解.非常支持你的做法,不過我現(xiàn)在覺得重構(gòu)到模式可能更能解決實(shí)際問題.你的目標(biāo)非常具體,是我的學(xué)習(xí)榜樣.希望我們以后能夠多交流  回復(fù)  更多評論
              

            > hi的博客
            人妻精品久久无码专区精东影业| 久久午夜无码鲁丝片| 亚洲AV无一区二区三区久久| 伊人久久大香线蕉综合5g| 一级女性全黄久久生活片免费 | 97精品依人久久久大香线蕉97| 久久婷婷五月综合色奶水99啪| 色8激情欧美成人久久综合电| 久久婷婷国产剧情内射白浆| 亚洲国产小视频精品久久久三级| 亚洲欧美精品一区久久中文字幕| 久久丝袜精品中文字幕| 亚洲国产精品久久电影欧美| 亚洲中文字幕无码久久2017| 久久精品麻豆日日躁夜夜躁| 久久久艹| 国产成人综合久久综合| 2020国产成人久久精品| 精品国产乱码久久久久久人妻| 无码精品久久久久久人妻中字| 精品熟女少妇a∨免费久久| 青青热久久国产久精品 | 2021国产精品午夜久久| 色综合久久久久综合体桃花网| 狠狠干狠狠久久| 无码人妻久久久一区二区三区| 国产精品一久久香蕉国产线看| 四虎国产精品免费久久5151| 亚洲国产精品无码久久| 亚洲AV日韩AV天堂久久| 国产精品免费久久久久久久久| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 99久久无码一区人妻a黑| 久久国产乱子精品免费女| 亚洲欧美成人久久综合中文网| 69久久夜色精品国产69| 理论片午午伦夜理片久久| 波多野结衣中文字幕久久| 亚洲欧美另类日本久久国产真实乱对白| 无码人妻久久一区二区三区 | 国产麻豆精品久久一二三|