interface IProtectedProxy { void Request(); }
保护代理接口
using System; class ProtectedProxy : IProtectedProxy { private string _Name; private IProtectedProxy _ProtectedTruthInstance; public ProtectedProxy(string name) { _Name = name; _ProtectedTruthInstance = new ProtectedTruthInstance(); } #region IProtectedProxy 成员 public void Request() { if (_Name == "GhostBear") { _ProtectedTruthInstance.Request(); } else { Console.WriteLine("you promision to access this method."); } } #endregion }
保护代理实现A
using System; class ProtectedTruthInstance : IProtectedProxy { public ProtectedTruthInstance() { } #region IProtectedProxy 成员 public void Request() { Console.WriteLine("you admision to access this method."); } #endregion }
被保护的对象
using System; using System.Collections.Generic; using System.Text; namespace ProxyPattern { class Program { static void Main(string[] args) { ProtectedProxy pp = new ProtectedProxy("Jim"); pp.Request(); Console.ReadKey(); } } }
调用者
451

被折叠的 条评论
为什么被折叠?



