Proxy 模式

namespace ProxyPursuit
{
    class Beauty
    {
        private string name;
        public string BeautyName
        {
            get;
            set;
        }
        public Beauty()
        {

        }
        public Beauty(string name2)
        {
            this.name = name2;
        }
    }
    interface GiveGift
    {
        void GiveFlower();
        void GiveChocolate();
        void GiveDolls();
    }
    class Pursuit:GiveGift
    {
        Beauty mm;
        public Pursuit(Beauty mm)
        {
            this.mm = mm;
        }
        public void GiveDolls()
        {
            Console.WriteLine("{0} ,Give you Dolls!", mm.BeautyName);
        }
        public void GiveChocolate()
        {
            Console.WriteLine("{0} ,Give you Chocolate!", mm.BeautyName);
        }
        public void GiveFlower()
        {
            Console.WriteLine("{0} ,Give you flowers!", mm.BeautyName);
        }
    }
    class Proxy : GiveGift
    {
        Pursuit gg;
        public Proxy(Beauty mm)
        {
            gg = new Pursuit(mm);

        }
        public void GiveChocolate()
        {
            gg.GiveChocolate();
        }
        public void GiveDolls()
        {
            gg.GiveDolls();
        }
        public void GiveFlower()
        {
            gg.GiveFlower();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            //Beauty zkj = new Beauty("zkj");
            Beauty zkj = new Beauty();
            zkj.BeautyName = "zkj";

            Proxy pro = new Proxy(zkj);
            pro.GiveDolls();
            pro.GiveFlower();
            pro.GiveChocolate();

            Console.Read();
        }
    }
}

posted on 2009-07-13 21:10  Acor  阅读(229)  评论(0编辑  收藏  举报

导航