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();
  • 相关阅读:
    分布式任务调度平台XXL-JOB搭建教程
    微服务跨域问题
    getway网关跨域问题记录
    MySQL-数据库简介及mysql5.7安装
    MongoDB-备份和恢复
    MongoDB-复制集rs及sharding cluster
    MongoDB
    Redis-API支持
    Redis-主从复制,哨兵机制及redis cluster
    Redis-简介及基本数据类型
  • 原文地址:https://www.cnblogs.com/alisande/p/5592476.html
Copyright © 2011-2022 走看看