singleton

singleton 模式是一种面向模式的全局变量创建方法,确保了在运行时只有singleton类的一个实例。
他还提供了一个全局访问点。
  在应用程序运行时,如果确定只需要一个对象实例,那么就应该使用singleton模式。

 class ExampleSingleton
{
       public void PrintHello()
            {
                System.Console.WriteLine(":");
            }
        private ExampleSingleton()
        {}
         static ExampleSingleton exampleSingleton=new ExampleSingleton();
        
         public static ExampleSingleton  Singleton{
            get{return exampleSingleton;}
        }

}

posted on 2005-11-01 09:18  井泉  阅读(235)  评论(0编辑  收藏  举报

导航