单例模式通用代码:
public class Singleton
{
//private const Singleton singleton = new Singleton();//.net
private static final Singleton singleton = new Singleton();//java
//私有的构造方法,限制产生多个对象
private Singleton()
{
}
//通过该方法获得实例对象
public static Singleton GetSingleton()
{
return singleton;
}
//类中其他方法,尽量是static
public static void doSomething()
{
}
}