设计模式之代理模式

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

namespace ProxyPattern
{
    interface IPeople
    {
        void Talk();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProxyPattern
{
    class People:IPeople
    {
        public void Talk()
        {
            Console.WriteLine("你好!");
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProxyPattern
{
    class ProxyPeople:IPeople
    {
        People people = null;
        public ProxyPeople(People p) {
            people = p;
        }
        public void Talk()
        {
            Console.WriteLine("让我们来段rap,what'up man");
            people.Talk();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProxyPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            People p = new People();
            ProxyPeople pp = new ProxyPeople(p);
            pp.Talk();
            Console.ReadLine();
        }
    }
}


你可能感兴趣的:(设计模式之代理模式)