private static void Main(string[] args) { //É POSSIVEL PEDIR LOGO AO REALSUBJECT var client = new Client(); Console.WriteLine("Client: Executing the client code with a real subject"); var realSubject = new RealSubject(); client.ClientCode(realSubject); Console.WriteLine(); //UTILIZANDO A PROXY PARA CONTROLAR O ACESSO Console.WriteLine("Client: Executing the same client code with the proxy"); var proxy = new Proxy(realSubject); client.ClientCode(proxy); Console.WriteLine(); //UTILIZANDO A PROXY PARA CONTROLAR O ACESSO DE OUTRAS SUBCLASSES O SUBJECT var diffSubject = new DifferentSubject(); Console.WriteLine("Client: Executing the same client code with the proxy"); proxy = new Proxy(diffSubject); client.ClientCode(proxy); Console.Read(); }
public override void Operation() { if (_realSubject == null) _realSubject = new RealSubject(); _realSubject.Operation(); }
public void Request() { if (RealSubject == null) { RealSubject = new RealSubject(this.Data); // Here you could get the data from the database, for example. } RealSubject.Request(); }
public override string Request() { if (realSubject == null) { realSubject = new RealSubject(); } return(realSubject.Request()); }
public override void Request() { if (_realSubject == null) { _realSubject = new RealSubject(); } _realSubject.Request(); }
public override void Request() { if (realsubject == null) { realsubject = new RealSubject(); } realsubject.Request(); }
public override void Request() { // Use 'lazy initialization' if (_realSubject == null) { _realSubject = new RealSubject(); } _realSubject.Request(); }
public override void Requisicao() { if (this.realSubject == null) { this.realSubject = new RealSubject(); } this.realSubject.Requisicao(); }
public override void Operation() { if (_realSubject == null) { _realSubject = new RealSubject(); } _realSubject.Operation(); }
public void DoOperation() { if (realSubject == null) { realSubject = new RealSubject(); } realSubject.DoOperation(); }
public override void Study() { if (real == null) { real = new RealSubject(); } Console.WriteLine("我是待你学习"); real.Study(); }
public override void Request() { if (realSubject == null) { realSubject = new RealSubject(); } realSubject.Request(); }
public override void Request() { //use lazy initialization if (_realSubject == null) { _realSubject = new RealSubject(); } _realSubject.Request(); }
public void RequestPassword() { if (CheckAccess()) { realSubject = new RealSubject(); realSubject.RequestPassword(); LogAccess(); } }
// The most common applications of the Proxy pattern are lazy loading, // caching, controlling the access, logging, etc. A Proxy can perform // one of these things and then, depending on the result, pass the // execution to the same method in a linked RealSubject object. public void Request() { if (this.CheckAccess()) { this._realSubject = new RealSubject(); this._realSubject.Request(); this.LogAccess(); } }
public void Request() { if (CheckAccess()) { _realSubject = new RealSubject(); _realSubject.Request(); LogAccess(); } }
public override void Request() { if (_realSubject == null) // lazy init { _realSubject = new RealSubject(); } _realSubject.Request(); }
static void Main(string[] args) { Console.WriteLine($"Executing the method with a real subject:"); RealSubject realSubject = new RealSubject(); realSubject.RequestPassword(); Console.WriteLine($"\nExecuting the method with a proxy:"); Proxy proxy = new Proxy(realSubject); proxy.RequestPassword(); }
public void DoHeavyLifting() { if (Auth(password)) { realThing = new RealSubject(); realThing.DoHeavyLifting(); } else { Console.WriteLine("Did not authenticate - controlling when a costly object needs to be instantiated and initialized"); } }
static void Main(string[] args) { Client client = new Client(); Console.WriteLine("Client: Executing the client code with a real subject:"); RealSubject realSubject = new RealSubject(); client.ClientCode(realSubject); Console.WriteLine(); Console.WriteLine("Client: Executing the same client code with a proxy:"); Pattern.Proxy proxy = new Pattern.Proxy(realSubject); client.ClientCode(proxy); }
static void Main(string[] args) { Subject subject = new RealSubject(); Subject proxy; Console.WriteLine("Role: Guest"); proxy = new ProxySubject(subject, Role.guest); Access(proxy); Console.WriteLine("\nRole: User"); proxy = new ProxySubject(subject, Role.user); Access(proxy); Console.WriteLine("\nRole: Administrator"); proxy = new ProxySubject(subject, Role.administrator); Access(proxy); Console.ReadKey(); }
static void Main(string[] args) { // canonical var subject = new RealSubject(); subject.Request(); var proxy = new Proxy.Canonical.Proxy(); proxy.Request(); // live Console.WriteLine(); var image = new ProxyImage("C://temp.jpq"); // will be loaded lazyly image.Display(); // wont be loaded 2nd time image.Display(); }
static void Main() { Subject subject = new RealSubject(); Subject proxy; Console.WriteLine("Owner work:"); proxy = new Proxy(subject, "Owner"); TryAccess(proxy, "John"); Console.WriteLine("Administrator work:"); proxy = new Proxy(subject, "Administrator"); TryAccess(proxy, "Mark"); Console.WriteLine("Manager work:"); proxy = new Proxy(subject, "Manager"); TryAccess(proxy, "Lola"); Console.WriteLine("User work:"); proxy = new Proxy(subject, "User"); TryAccess(proxy, "Gigi"); // Delay. Console.ReadKey(); }
public override void Request() { //实例一个真实用户 realSubject = new RealSubject(); realSubject.Request();//调用真实用户的方法 }
public Proxy(RealSubject realSubject) { _realSubject = realSubject; }
public Proxy(RealSubject realSubject) { this._realSubject = realSubject; }
public Proxy(RealSubject realsubject) { realsubject = realSubject; }
public void Send() { this._realSubject = new RealSubject(); this._realSubject.Send(); }