zoukankan      html  css  js  c++  java
  • 设计模式-10-装饰者

    说明

    1.建立抽象组件

    2.建立抽象装饰着者继承于抽象组件并在构造器聚合抽象组件

    3.具体装饰者继承抽象装饰者和具体组件继承抽象组件,达到在一个具体组件上层增加很多个具体的具体装饰者,给这个具体组件动态的附加很多功能

     public abstract class AbsComponent
        {
            public abstract void Exc();
        }
     public abstract class AbsDecorator:AbsComponent
        {
            protected AbsComponent absComponent;
            public AbsDecorator(AbsComponent absComponent)
            {
                this.absComponent = absComponent;
            }
            public override void Exc()
            {
                if(absComponent!=null)
                {
                    absComponent.Exc();
                }
            }
        }
     class Component : AbsComponent
        {
            public override void Exc()
            {
                Console.WriteLine("执行Component完成");
            }
        }
     class DecoratorA : AbsDecorator
        {
            public DecoratorA(AbsComponent absComponent) : base(absComponent)
            {
            }
    
            public override void Exc()
            {
                Console.WriteLine("DecoratorA执行完成");
                base.Exc();
            }
    
          
        }
     class DecoratorB : AbsDecorator
        {
            public DecoratorB(AbsComponent absComponent) : base(absComponent)
            {
            }
    
            public override void Exc()
            {
                Console.WriteLine("正在配置DecoratorB");
                Console.WriteLine("DecoratorB执行完成");
                base.Exc();
            }
    
          
        }
    new DecoratorA(new DecoratorB(new Component())).Exc();
  • 相关阅读:
    mysql查询两个日期之前相隔的天数
    数据库脏读、不可重读读、幻读
    kafka手动开启监听
    oracle更具uuid排序后进行分页
    idea右键没有svn选项
    alibaba dubbo admin的安装
    简单的可以跑起来的dubbo例子
    tomcat配置内存
    redis介绍和安装
    Python深入:Distutils发布Python模块
  • 原文地址:https://www.cnblogs.com/alisande/p/5592476.html
Copyright © 2011-2022 走看看