Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                {
                    //new 一个对象  站着一些资源  但是干别的事儿去了
                    ISubject subject = new RealSubject();   // new 数据库连接
                    Console.WriteLine("do something else"); // 准备一些参数, 做一些判断
                    Console.WriteLine("do something else"); // new command 拼装 SQL
                    Console.WriteLine("do something else");
                    subject.GetSomethingLong();
                    subject.DoSomethingLong();
                }

                {
                    ISubject subject = new ProxySubject();
                    subject.GetSomethingLong();
                    subject.DoSomethingLong();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ProxySubject proxySubject = new ProxySubject(new RealSubject());

            proxySubject.Execute();

            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ISubject subject = new RealSubject();

            subject.Get();
            subject.Do();

            ISubject pSubject = new ProxySubject();

            pSubject.Get();
            pSubject.Do();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            try
            {
                {
                    Console.WriteLine("***********Real**************");

                    ISubject subject = new RealSubject();//持有资源 /数据库链接

                    Console.WriteLine("do something else...");
                    Thread.Sleep(500);
                    Console.WriteLine("do something else...");
                    Console.WriteLine("do something else...");
                    Console.WriteLine("do something else...");
                    //subject.GetSomething();
                    subject.DoSomething();
                }
                {
                    Console.WriteLine("***********Proxy1**************");
                    ISubject subject = new ProxySubject();

                    Console.WriteLine("do something else...");
                    Thread.Sleep(500);
                    Console.WriteLine("do something else...");
                    Console.WriteLine("do something else...");
                    Console.WriteLine("do something else...");

                    //subject.GetSomething();//真的需要的时候,才去   持有资源 /数据库链接
                    subject.DoSomething();
                }
                {
                    Console.WriteLine("***********Proxy1**************");
                    ISubject subject = new ProxySubject();

                    subject.GetSomething();
                    subject.DoSomething();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("欢迎来到.net高级班公开课之设计模式特训,今天是Eleven老师为大家带来的代理模式");

                Console.WriteLine("********************");
                {
                    ISubject realSubject = new RealSubject();
                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");
                    realSubject.GetSomething();
                    realSubject.GetSomething();
                    realSubject.DoSomething();
                }
                Console.WriteLine("********************");
                {
                    ISubject proxySubject = new ProxySubject();


                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");
                    Console.WriteLine("干点别的");

                    proxySubject.GetSomething();
                    proxySubject.GetSomething();
                    proxySubject.GetSomething();
                    proxySubject.GetSomething();
                    proxySubject.DoSomething();
                }

                ServiceReference1.SearcherClient client = new ServiceReference1.SearcherClient();
                //client.QueryCommodityPage();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Esempio n. 6
0
        public void Run()
        {
            ProxySubject proxy = new ProxySubject();

            proxy.Request();
        }