zoukankan      html  css  js  c++  java
  • 代理模式

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace Proxy
    {
     
        /// <summary>
        /// 被追求者类
        /// </summary>
        class SchoolGirl
        {
            private string name;
     
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
     
        }
     
        /// <summary>
        /// 送礼物接口
        /// </summary>
        interface IGiveGift
        {
            void GiveDolls();
            void GiveFlowers();
            void GiveChocolate();
        }
     
        /// <summary>
        /// 追求者类
        /// </summary>
        class Pursuit : IGiveGift
        {
            SchoolGirl mm;
            public Pursuit(SchoolGirl mm)
            {
                this.mm = mm;
            }
     
            public void GiveDolls()
            {
                Console.WriteLine(mm.Name + ",送你洋娃娃!");
            }
     
            public void GiveFlowers()
            {
                Console.WriteLine(mm.Name + ",送你鲜花!");
            }
     
            public void GiveChocolate()
            {
                Console.WriteLine(mm.Name + ",送你巧克力!");
            }
        }
        /// <summary>
        /// 代理类
        /// </summary>
        class Proxy : IGiveGift
        {
            Pursuit gg;
            public Proxy(SchoolGirl mm)
            {
                gg = new Pursuit(mm);
            }
     
            public void GiveDolls()
            {
                gg.GiveDolls();
            }
     
            public void GiveFlowers()
            {
                gg.GiveFlowers();
            }
     
            public void GiveChocolate()
            {
                gg.GiveChocolate();
            }
        }
     
        class Program
        {
            static void Main(string[] args)
            {
                SchoolGirl yatou = new SchoolGirl();
                yatou.Name = "丫头";
     
                Proxy zhutou = new Proxy(yatou);
                zhutou.GiveChocolate();
                zhutou.GiveDolls();
                zhutou.GiveFlowers();
     
                Console.Read();
            }
        }
    }
  • 相关阅读:
    [BZOJ 4318] OSU!
    [BZOJ 4720][NOIP 2016] 换教室
    [Tyvj 1729] 文艺平衡树
    [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]
    [学习笔记] CDQ分治 从感性理解到彻底晕菜
    [COGS 1752] 摩基亚Mokia
    [Tyvj 1730] 二逼平衡树
    [学习笔记] Splay Tree 从入门到放弃
    [Tyvj 1728] 普通平衡树
    [BZOJ 3594] 方伯伯的玉米田
  • 原文地址:https://www.cnblogs.com/loveyatou/p/2970541.html
Copyright © 2011-2022 走看看