The 'RealSubject' class
Inheritance: Subject
Example #1
0
        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();
        }
Example #2
0
        public override void Operation()
        {
            if (_realSubject == null)
                _realSubject = new RealSubject();

            _realSubject.Operation();
        }
Example #3
0
 public void Request()
 {
     if (RealSubject == null)
     {
         RealSubject = new RealSubject(this.Data); // Here you could get the data from the database, for example.
     }
     RealSubject.Request();
 }
Example #4
0
 public override string Request()
 {
     if (realSubject == null)
     {
         realSubject = new RealSubject();
     }
     return(realSubject.Request());
 }
Example #5
0
 public override void Request()
 {
     if (_realSubject == null)
     {
         _realSubject = new RealSubject();
     }
     _realSubject.Request();
 }
Example #6
0
 public override void Request()
 {
     if (realsubject == null)
     {
         realsubject = new RealSubject();
     }
     realsubject.Request();
 }
Example #7
0
        public override void Request()
        {
            // Use 'lazy initialization'
            if (_realSubject == null) {
                _realSubject = new RealSubject();
            }

            _realSubject.Request();
        }
Example #8
0
        public override void Requisicao()
        {
            if (this.realSubject == null)
            {
                this.realSubject = new RealSubject();
            }

            this.realSubject.Requisicao();
        }
Example #9
0
        public override void Operation()
        {
            if (_realSubject == null)
            {
                _realSubject = new RealSubject();
            }

            _realSubject.Operation();
        }
Example #10
0
        public void DoOperation()
        {
            if (realSubject == null)
            {
                realSubject = new RealSubject();
            }

            realSubject.DoOperation();
        }
Example #11
0
 public override void Study()
 {
     if (real == null)
     {
         real = new RealSubject();
     }
     Console.WriteLine("我是待你学习");
     real.Study();
 }
Example #12
0
        public void DoOperation()
        {
            if (realSubject == null)
            {
                realSubject = new RealSubject();
            }

            realSubject.DoOperation();
        }
Example #13
0
        public override void Request()
        {
            if (realSubject == null)
            {
                realSubject = new RealSubject();
            }

            realSubject.Request();
        }
Example #14
0
 public override void Request()
 {
     //use lazy initialization
     if (_realSubject == null)
     {
         _realSubject = new RealSubject();
     }
     _realSubject.Request();
 }
Example #15
0
        public void RequestPassword()
        {
            if (CheckAccess())
            {
                realSubject = new RealSubject();
                realSubject.RequestPassword();

                LogAccess();
            }
        }
Example #16
0
        // 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();
            }
        }
Example #17
0
        public void Request()
        {
            if (CheckAccess())
            {
                _realSubject = new RealSubject();
                _realSubject.Request();

                LogAccess();
            }
        }
Example #18
0
        public override void Request()
        {
            if (_realSubject == null)   // lazy init
            {
                _realSubject = new RealSubject();
            }

            _realSubject.Request();

        }
Example #19
0
        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();
        }
Example #20
0
 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");
     }
 }
Example #21
0
        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);
        }
Example #22
0
        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();
        }
Example #23
0
        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();
        }
Example #24
0
        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();
        }
Example #25
0
 public override void Request()
 {
     //实例一个真实用户
     realSubject = new RealSubject();
     realSubject.Request();//调用真实用户的方法
 }
Example #26
0
 public Proxy(RealSubject realSubject)
 {
     _realSubject = realSubject;
 }
Example #27
0
 public Proxy(RealSubject realSubject)
 {
     this._realSubject = realSubject;
 }
Example #28
0
 public Proxy(RealSubject realsubject)
 {
     realsubject = realSubject;
 }
 public void Send()
 {
     this._realSubject = new RealSubject();
     this._realSubject.Send();
 }