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

            _realSubject.Operation();
        }
Esempio n. 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();
 }
Esempio n. 4
0
 public override string Request()
 {
     if (realSubject == null)
     {
         realSubject = new RealSubject();
     }
     return(realSubject.Request());
 }
Esempio n. 5
0
 public override void Request()
 {
     if (_realSubject == null)
     {
         _realSubject = new RealSubject();
     }
     _realSubject.Request();
 }
Esempio n. 6
0
 public override void Request()
 {
     if (realsubject == null)
     {
         realsubject = new RealSubject();
     }
     realsubject.Request();
 }
Esempio n. 7
0
        public override void Request()
        {
            // Use 'lazy initialization'
            if (_realSubject == null) {
                _realSubject = new RealSubject();
            }

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

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

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

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

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

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

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

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

            _realSubject.Request();

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