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

            linux&c++ R&D

            programing is a pleasure!

            Understand decorator design pattern

                The Decorator Pattern is used for adding additional functionality to a particular object as opposed to a class of objects. It is easy to add functionality to an entire class of objects by subclassing an object, but it is impossible to extend a single object this way. With the Decorator Pattern, you can add functionality to a single object and leave others like it unmodified.
               A Decorator, also known as a Wrapper, is an object that has an interface identical to an object that it contains. Any calls that the decorator gets, it relays to the object that it contains, and adds its own functionality along the way, either before or after the call. This gives you a lot of flexibility, since you can change what the decorator does at runtime, as opposed to having the change be static and determined at compile time by subclassing. Since a Decorator complies with the interface that the object that it contains, the Decorator is indistinguishable from the object that it contains.  That is, a Decorator is a concrete instance of the abstract class, and thus is indistinguishable from any other concrete instance, including other decorators.   This can be used to great advantage, as you can recursively nest decorators without any other objects being able to tell the difference, allowing a near infinite amount of customization.



            An example:

            #include <iostream>
            class IntCompute{
            public:
                virtual 
            int Compute(int,int=0;
            }
            ;
            class IntComputeAdd:public IntCompute{
            public:
            int Compute(int a,int b){
                
            return a+b;
            }

            }
            ;
            class DecorateMinusAdd:public IntCompute{
            private:
                IntComputeAdd intadd;
            public:
                
            int Compute(int a,int b)
                
            {
                  
            return -(intadd.Compute(a,b));

                }

            }
            ;
            class DecorateSumSquare:public IntCompute{
            private:
                IntComputeAdd intadd;
            public:
                
            int Compute(int a,int b)
                
            {
                    
            int result=intadd.Compute(a,b);
                    
            return result*result;

                }

            }
            ;
            int main()
            {
             
            DecorateMinusAdd minadd;
            DecorateSumSquare sumsquare;
            std::cout
            <<minadd.Compute(10,20)<<std::endl;
            std::cout
            <<sumsquare.Compute(10,20)<<std::endl;
             
            return 0;
            }

            posted on 2007-05-11 21:38 丑石 閱讀(475) 評論(0)  編輯 收藏 引用 所屬分類: software engineering

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            人人妻久久人人澡人人爽人人精品 | 久久久久亚洲精品中文字幕| 国产精品美女久久久网AV| 国产精品欧美久久久久天天影视| 国产99久久久国产精免费| 天堂无码久久综合东京热| 久久久精品国产sm调教网站| 国产日韩欧美久久| 人妻久久久一区二区三区| 久久精品国产半推半就| 久久99热这里只有精品国产| 777久久精品一区二区三区无码| 欧洲国产伦久久久久久久| 国产麻豆精品久久一二三| 亚洲国产成人久久精品99 | 思思久久99热只有频精品66| 久久久久99精品成人片欧美| 亚洲Av无码国产情品久久| 国产精品一久久香蕉国产线看观看| 久久精品成人免费国产片小草| 一本久久知道综合久久| 色偷偷88欧美精品久久久| 亚洲午夜久久影院| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 精品国产乱码久久久久久呢| 伊人久久精品线影院| 99久久久精品免费观看国产| 一级a性色生活片久久无少妇一级婬片免费放 | 久久久久亚洲av综合波多野结衣| 久久久久亚洲av成人无码电影| 热久久这里只有精品| 91精品国产乱码久久久久久| 国产成人精品综合久久久| 久久久久久久97| 久久精品国产99国产精品导航 | 狠狠色丁香久久婷婷综| 麻豆亚洲AV永久无码精品久久| 国内高清久久久久久| 国产亚洲精久久久久久无码77777| 久久人妻AV中文字幕| 亚洲AV日韩AV永久无码久久|