设计模式:代理模式

代理模式(Proxy):为其他对象提供一种代理以控制对这个对象的访问。

namespace ProxyDesignPattern
{
    public abstract class Subject
    {
        public abstract void Request();
    }
    public class RealSubject:Subject
    {
        public override void Request()
        {
            Console.WriteLine("真实的请求");
        }
    }
    public class Proxy:Subject
    {
        RealSubject realSubject;
        public override void Request()
        {
            if (realSubject == null)
            {
                realSubject = new RealSubject();        
            }
            realSubject.Request();
        }
    }
}
View Code

测试代码:

            Proxy proxy = new Proxy();
            proxy.Request();
View Code

 

posted @ 2016-03-08 13:56  uptothesky  阅读(119)  评论(0编辑  收藏  举报