设计模式:代理模式
代理模式(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(); } } }
测试代码:
Proxy proxy = new Proxy(); proxy.Request();