八.代理模式

代理模式:

       隐藏真实模块。

方法:

       //抽象类

   abstract  class Subject

    {

       public abstract void Request();

    }

   //真实实现类

   class RealSubject : Subject

    {

       public override void Request()

       {

           Console.WriteLine("真实的请求");

       }

    }

   //代理类

   class Proxy : Subject

    {

       RealSubject realsubject;

       public override void Request()

       {

           if (realsubject == null)

           {

                realsubject = newRealSubject();

           }

           realsubject.Request();

       }

}

       classProgram

    {

       //代理模式

       static void Main(string[] args)

       {

           Proxy proxy = new Proxy();

           proxy.Request();

           Console.ReadKey();

       }

    }

posted @ 2010-09-01 20:17  耀哥  阅读(209)  评论(0编辑  收藏  举报