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

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace 装饰模式
    {
        class Person
        {
            public Person()
            {
            }

            private string name;
            public Person(string name)
            {
                this.name = name;
            }

            public virtual void Show()
            {
                Console.WriteLine("装扮的{0}", name);
            }
        }

        class Finery : Person
        {
            protected Person component;

            //打扮
            public void Decorate(Person component)
            {
                this.component = component;
            }

            public override void Show()
            {
                if (component != null)
                {
                    component.Show();
                }
            }
        }

        class TShirts : Finery
        {
            public override void Show()
            {
                Console.Write("大T-Shirt ");
                base.Show();
            }
        }

        class BigTrouser : Finery
        {
            public override void Show()
            {
                Console.Write("垮裤 ");
                base.Show();
            }
        }

        class Sneakers: Finery
        {
            public override void Show()
            {
                Console.Write("破球鞋 ");
                base.Show();
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                Person ps = new Person("小江");

                Sneakers sn = new Sneakers();
                BigTrouser bt = new BigTrouser();
                TShirts ts = new TShirts();

                sn.Decorate(ps);
                bt.Decorate(sn);
                ts.Decorate(bt);

                ts.Show();
            }
        }
    }

    明确个目标,一直走下去
  • 相关阅读:
    关于Hibernate(JPA)关联关系加载的默认值
    (转)存储过程语法及实例
    网页qq
    git的代理配置
    The problem with POSIX semaphores 使用信号做进程互斥必看
    git merge conflict的处理
    转载:telnet协议详细描述
    Mac OS X terminal滚动慢的问题
    进程间通讯 信号量函数 semget() semop() semctl()
    .hpp文件和.h文件的区别
  • 原文地址:https://www.cnblogs.com/fhlj/p/3613684.html
Copyright © 2011-2022 走看看