• <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这里有精品10 | 97久久精品无码一区二区天美| 久久人与动人物a级毛片| 久久久久久国产精品美女| 久久亚洲私人国产精品vA| 国产精品久久毛片完整版| 精品人妻伦九区久久AAA片69| 久久久久久无码国产精品中文字幕| 久久综合中文字幕| 无码AV中文字幕久久专区| 国产精品VIDEOSSEX久久发布| 狠狠色丁香婷婷久久综合| 精品精品国产自在久久高清| 狠狠人妻久久久久久综合蜜桃| 亚洲Av无码国产情品久久| 人妻精品久久无码专区精东影业| 久久精品无码av| 国产精品久久久天天影视香蕉| 久久久久久久人妻无码中文字幕爆| 久久久久九九精品影院| 欧美日韩成人精品久久久免费看| 久久99国产精一区二区三区| 久久久亚洲欧洲日产国码aⅴ| 久久精品国产免费观看| 狠狠色丁香久久婷婷综合_中| 久久99国产精品久久99小说| 久久人人爽人爽人人爽av| 要久久爱在线免费观看| 热RE99久久精品国产66热| 综合久久给合久久狠狠狠97色 | 亚洲精品第一综合99久久| 久久精品国产亚洲Aⅴ香蕉| 久久综合九色欧美综合狠狠| 国产成人久久777777| 久久久久久久97| 久久天天躁狠狠躁夜夜躁2O2O| 久久精品国内一区二区三区| 久久国产视屏|