public static void Main(String[] args) { //ProxySubject subject = new ProxySubject(new RealSubject()); VirtualProxy subject = new VirtualProxy("XiaoMing"); subject.Visit(); }
private static void VirtualProxySample() { IExampleExpensiveObject withProxy = new VirtualProxy("JIT"); IExampleExpensiveObject withoutProxy = new ExampleExpensiveObject("AOT"); Console.WriteLine(withoutProxy.Text); Console.WriteLine(withProxy.Text); }
public ProxyViewModel() { IProductSubject proxy = new VirtualProxy(); var items = proxy.GetProductRequest(); this.ModelName = items.ModelName; this.Price = items.Price; this.Warranty = items.Warranty; }
public void Proxy() { RealSubject realsubject = new RealSubject(); Assert.AreEqual(realsubject.DoAction(), "do action"); VirtualProxy subject = new VirtualProxy(); Assert.AreEqual(subject.DoAction(), "Virtual Proxy: Call to do action"); ProtectionProxy protectedsubject = new ProtectionProxy(); Assert.AreEqual(protectedsubject.DoAction(), "Protection Proxy: Authenticate first"); var result = protectedsubject.Authenticate("somepassword"); Assert.AreEqual(result, "Protection proxy: No Access"); Assert.AreEqual(protectedsubject.DoAction(), "Protection Proxy: Authenticate first"); result = protectedsubject.Authenticate("mypassword"); Assert.AreEqual(result, "Protection proxy: Authenticated"); Assert.AreEqual(protectedsubject.DoAction(), "Protection Proxy: Call to do action"); }