ITeye博客

单例模式(Singleton)

langyan · 2012-06-15 14:17 · theory · 编程语言 · Markdown

单例模式:

一.特点

 

1. 只能有一个实例。

2. 必须由自己创建唯一的实例

二.条件

 

    在一个系统要求一个类只有一个实例时,才应当使用单例模式

 

三.案例

 

package java.lang;

public class Runtime {
    private static Runtime currentRuntime = new Runtime();

   /** Don't let anyone else instantiate this class */
    private Runtime() {}

    public static Runtime getRuntime() { 
	return currentRuntime;
    }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。