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();
            }
        }
    }
  • 相关阅读:
    bestcoder #66
    uva11093 Just Finish it up
    UVA 12627 Erratic Expansion
    uva714 Copying Books
    龟兔赛跑
    神、上帝以及老天爷
    不容易系列之(3)―― LELE的RPG难题
    C. Watto and Mechanism
    Phone List hdu1671
    B. Han Solo and Lazer Gun
  • 原文地址:https://www.cnblogs.com/loveyatou/p/2970541.html
Copyright © 2011-2022 走看看