• <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 丑石 閱讀(479) 評論(0)  編輯 收藏 引用 所屬分類: software engineering

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            色综合久久久久网| 亚洲日韩中文无码久久| 99久久精品国产毛片| 久久人妻少妇嫩草AV蜜桃| 亚洲人成精品久久久久| 久久青草国产精品一区| 亚洲伊人久久成综合人影院 | 青青草国产97免久久费观看| 久久久亚洲裙底偷窥综合| 777米奇久久最新地址| 色婷婷久久久SWAG精品| 91精品国产高清91久久久久久| 欧美亚洲日本久久精品| 久久99免费视频| 久久久久亚洲AV无码网站| 麻豆久久| 精品久久国产一区二区三区香蕉| 久久久久人妻精品一区二区三区 | 久久久久久亚洲精品不卡| 久久久一本精品99久久精品88| 久久婷婷五月综合色99啪ak| 国内精品久久人妻互换| 久久人妻AV中文字幕| 青春久久| 模特私拍国产精品久久| 久久久久久久久久久免费精品 | 99久久国产综合精品麻豆| 99久久精品免费看国产一区二区三区 | 精品久久久久久无码中文野结衣| 精品蜜臀久久久久99网站| 久久精品国产2020| 久久香综合精品久久伊人| 亚洲欧美另类日本久久国产真实乱对白 | 久久精品99久久香蕉国产色戒 | 亚洲AV无码久久| 性色欲网站人妻丰满中文久久不卡| 久久久久这里只有精品| 久久综合色区| 久久人人爽人人爽人人片AV不 | 欧美精品福利视频一区二区三区久久久精品 | 亚洲午夜久久久久久久久久|