static void Main(string[] args)
    {
        Console.WriteLine("Proxy Pattern\n");

        ISubject proxyA = new ProxyA();
        Console.WriteLine(proxyA.Request());

        ProtectedProxy subject = new ProtectedProxy();
        Console.WriteLine(subject.Request());
        Console.WriteLine(subject.Authenticate("abc"));
        Console.WriteLine(subject.Authenticate("abc123"));
        Console.WriteLine(subject.Request());

        Console.ReadLine();

        /*
         * Output:
         *
         * Proxy Pattern
         *
         * Subject inactive
         * Subject activated
         * Proxy A: Call - Subject request response
         *
         * Protected Proxy: Must authenticated first
         * Protected Proxy: No access
         * Protected Proxy: Authenticated
         * Protected Proxy: Call - Subject request response
         *
         */
    }
Beispiel #2
0
        /***
         * In the case of a proxy class within c# it feels prudent to say that the they essentially
         * just encapsulate further functionality or protect sensitive data.
         *
         * It's also useful to assert that you could use this pattern as a means to encapsulate high
         * risk classes and functionality within a sophisticated build where there is continous development
         * where developers are exspected to decorate or stategy out functionality.
         *
         ***/
        private static void SimpleProxy()
        {
            ISubject subject = new Proxy();

            Console.WriteLine(subject.Request());
            Console.ReadLine();

            ProtectedProxy protectedSubject = new ProtectedProxy();

            Console.WriteLine(protectedSubject.Request());
            Console.WriteLine(protectedSubject.Authenticate("DumDeeDa"));
            Console.ReadLine();
        }