コード例 #1
0
        public static void BuildConcreteComponent()
        {
            ConcreteComponent concreteComponent = new ConcreteComponent();
            DecoratorA        _decoratorA       = new DecoratorA();
            DecoratorB        _decoratorB       = new DecoratorB();

            _decoratorA.SetComponent(concreteComponent);
            _decoratorB.SetComponent(_decoratorA);
            _decoratorB.Operation();
        }
コード例 #2
0
        static void Run()
        {
            //实例化实现类
            ConcreteComponent concrete = new ConcreteComponent();
            //实例化装饰类
            ConcreteDecoratorA decoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB decoratorB = new ConcreteDecoratorB();

            //用装饰类装饰实现类
            decoratorA.SetComponent(concrete);
            decoratorB.SetComponent(decoratorA);

            //
            decoratorB.Operation();
        }