• <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>
            隨筆 - 25  文章 - 29  trackbacks - 0
            <2006年9月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            1234567

            常用鏈接

            留言簿(4)

            隨筆分類(lèi)(22)

            隨筆檔案(25)

            文章分類(lèi)(2)

            文章檔案(2)

            相冊(cè)

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 56389
            • 排名 - 404

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            ?

            ?1 #pragma?once
            ?2
            ?3 class?component
            ?4 {
            ?5 public :
            ?6 ????component(void);
            ?7 ??virtual?void?printsefl() = 0 ???;
            ?8 public :
            ?9 ????virtual?~component(void);
            10 };
            11
            12 class?concreatecom?: public ?component
            13 {
            14 public :
            15 ????concreatecom(char * ?);
            16 ??virtual?void?printsefl()???;
            17 ??virtual?~concreatecom(void);
            18 protected:
            19 private :
            20 char? * ?_psz_text;
            21 };
            22
            23 class?decorator: public ?component
            24 {
            25 public :
            26 ?????decorator(component & );
            27 ??virtual?void?printsefl()?????;
            28 ??virtual?~decorator();
            29 protected:
            30
            31 private :
            32 ???component? & ?_pcomponent;
            33 };
            34 class??headdeco: public ?decorator
            35 {
            36 public :
            37 ???????headdeco(component & , int );
            38 ???virtual?void?printsefl()???;
            39 ???virtual?~headdeco();
            40 protected:
            41 ????virtual?void?printhead()??;
            42 private :
            43 int ?_i_head;
            44 };
            45
            46 class?enddeco: public ?decorator
            47 {
            48 public :
            49 ??????enddeco(component & ,char * );
            50 ????virtual?void?printsefl()?;
            51 ????virtual??~enddeco();
            52 protected:
            53 ??????virtual?void?printend()?;
            54 private :
            55 ?char * ?_pch_end;
            56 };

            ?1 #include? " StdAfx.h "
            ?2 #include? < iostream >
            ?3 #include? " component.h "
            ?4 using?namespace?std;
            ?5
            ?6 component::component(void)
            ?7 {
            ?8 }
            ?9
            10 component::~component(void)
            11 {
            12 }
            13
            14 void?concreatecom::printsefl()?
            15 {
            16 ???cout << endl;
            17 ???cout << _psz_text?;
            18 ???cout << endl;
            19 }
            20 ?concreatecom::concreatecom(char * ?psz)
            21 {
            22 ??????_psz_text = psz;
            23 }
            24 ?decorator::decorator(component & ?a):
            25 ???_pcomponent(a)
            26 {
            27 ??
            28 }
            29 concreatecom::~concreatecom()
            30 {
            31
            32 }
            33 void?decorator::printsefl()
            34 {
            35 _pcomponent.printsefl();
            36 ????
            37 }
            38
            39 decorator::~decorator()
            40 {
            41
            42 }
            43
            44 ?headdeco::headdeco(component? & ?refcom,? int ?i):
            45 ??decorator(refcom)
            46 ?,_i_head(i)
            47 {
            48
            49 }
            50 void?headdeco::printsefl()?
            51 {?
            52 ???printhead();
            53 ???decorator::printsefl();
            54 ???
            55 }
            56 void?headdeco::printhead()?
            57 {
            58 ????cout << endl;
            59 ???cout << _i_head;
            60 ???cout << endl;
            61 }
            62 headdeco::~headdeco()
            63 {
            64 ?
            65 }
            66
            67 enddeco::enddeco(component? & ?refcom,char? * ?pch)
            68 :decorator(refcom)
            69 ,_pch_end(pch)
            70 {
            71 ???
            72 }
            73 void?enddeco::printsefl()?
            74 {
            75 ????decorator::printsefl();
            76 ????printend();
            77 }
            78 void?enddeco::printend()??
            79 {
            80 ????cout << endl;
            81 ????cout << _pch_end;
            82 ????cout << endl;
            83 }
            84 enddeco::~enddeco()
            85 {
            86
            87 }
            ?1 // ?decorator.cpp?:?定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
            ?2 //
            ?3
            ?4 #include? " stdafx.h "
            ?5 #include? < iostream >
            ?6 #include? " component.h "
            ?7 using?namespace?std;
            ?8
            ?9 ?void?printmodel(component & ?pcom?)
            10 {
            11 ????pcom.printsefl();
            12 }
            13 int ?_tmain( int ?argc,?_TCHAR * ?argv[])
            14 {
            15 ?????
            16 ????printmodel(headdeco(headdeco(enddeco(concreatecom( " 正文輸出中。。。。 " ), " 黃大仙 " ), 2 ), 1 ));
            17 ????return? 0 ;
            18 }
            19



            ?????? 這個(gè)decorator 模式例子讓初學(xué)者 更能加深 多態(tài)威力的體會(huì)和 decorator 模式 比子類(lèi)靈活的體會(huì)
            要注意的問(wèn)題是:對(duì)象鏈總是在 concreatecomponent? 對(duì)象處結(jié)束。

            ? ///此處是client 使用 對(duì)象的入口點(diǎn),僅僅得到了 1個(gè) decorator 的派生類(lèi)對(duì)象,client 什么都不知道
            printmodel(headdeco(headdeco(enddeco(concreatecom("正文輸出中。。。。"),"黃大仙"),2),1));
            ///

            ???? 在vc2005 下通過(guò)

            posted on 2007-03-22 09:56 黃大仙 閱讀(2125) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): c++

            FeedBack:
            # re: 一個(gè) Decorator 模式 例子(原) 2007-03-23 09:17 Galaxy
            不錯(cuò) , 半年前看過(guò)decorator模式,
            看了你的例子, 呵呵, 理解的更深了
              回復(fù)  更多評(píng)論
              
            99久久综合狠狠综合久久| 午夜精品久久久内射近拍高清 | 996久久国产精品线观看| 久久精品免费观看| 久久久久青草线蕉综合超碰| 久久久久久人妻无码| 思思久久99热免费精品6| 99精品久久精品| 精品综合久久久久久97| 91精品国产91久久| 久久精品午夜一区二区福利| 久久人人爽人人爽人人片AV麻豆| 久久综合精品国产二区无码| 性做久久久久久免费观看| 久久er热视频在这里精品| 亚洲中文字幕久久精品无码喷水 | 久久国产一区二区| 亚洲国产精品无码久久98| 久久久久噜噜噜亚洲熟女综合 | 欧美一区二区久久精品| 久久久九九有精品国产| 国内精品久久久人妻中文字幕| 亚洲国产精品无码久久九九| 国产激情久久久久影院老熟女| 日韩精品久久无码人妻中文字幕| 午夜精品久久久久| 日韩久久久久中文字幕人妻 | 亚洲精品无码久久久久| 麻豆久久久9性大片| 久久久这里有精品| 一本大道久久东京热无码AV | 中文精品久久久久人妻不卡| 性做久久久久久免费观看| 久久人妻少妇嫩草AV无码蜜桃| 国产午夜电影久久| 九九热久久免费视频| 久久99精品久久久久久秒播| 国产精品丝袜久久久久久不卡| 狠狠人妻久久久久久综合| 久久天天躁狠狠躁夜夜2020老熟妇| 国产成人无码精品久久久免费 |