zoukankan      html  css  js  c++  java
  • 装饰器模式

        /// <summary>
        /// 抽象类 
        /// </summary>
        public abstract class Animal
        {
            public abstract void Show();
        }
        public class Dog : Animal
        {
            public override void Show()
            {
                Console.WriteLine("我是狗");
            }
        }
     /// <summary>
        /// 装饰器吃的
      /// <summary>
        /// 装饰器爱好
        /// </summary>
        public class HobbyDecorator : Animal
        {
            private Animal _animal = null;
            public HobbyDecorator(Animal animal)
            {
         static void Main(string[] args)
            {
                ///装饰器添加属性
                Animal dog = new Dog();
                dog = new HobbyDecorator(dog);
                dog = new EatDecorator(dog);
                dog.Show();
                Console.ReadKey();
            }
    
    
    
    this._animal = animal;
            }
            public override void Show()
            {
                //调用父类的方法
                this._animal.Show();
                Console.WriteLine("比较喜欢吃屎");
    
            }
        }
    
    
    
    方法
        /// </summary>
        public class EatDecorator : Animal
        {
            public Animal _animal = null;
            public EatDecorator(Animal animal)
            {
                _animal = animal;
            }
            public override void Show()
            {
                _animal.Show();
                Console.WriteLine("喜欢吃骨头");
            }
        }
  • 相关阅读:
    链式前向星啊
    并 查 集 ! ! !
    看似很水的题--找画笔
    tarjan
    动态内存分配
    C++ 基础中的基础 ---- 引用
    STL 补档
    错题笔记和易错点提醒
    题解 P2253 【好一个一中腰鼓!】
    PAT-A1003
  • 原文地址:https://www.cnblogs.com/zxp6/p/9291916.html
Copyright © 2011-2022 走看看