单例模式

1.Singleton(单例)
作用:保证类只有一个实例;提供一个全局访问点
JDK中体现:
(1)Runtime
(2)NumberFormat
类图:

public class Singleton {
    private static Singleton instance=new Singleton();
    private Singleton()
    {
        
    }
    public static Singleton newInstance()
    {
        return instance;
    }
}
View Code

 

posted @ 2017-07-25 22:39  连先森  阅读(86)  评论(0编辑  收藏  举报