2008-05-25

单例模式

关键字: 设计模式
package com.spsoft.singleton;

class Single {
	public void say() {
		System.out.println("I want to say,love you...");
	}
	/*private constructor method*/
	private Single() {
	}

	private static Single single = null;
	
	public static Single getSingleInstance() {
		if (single == null) {
			single = new Single();
		}
		return single;
	}
}

public class SingletenDemo {
	public static void main(String[] args) {
		Single s = Single.getSingleInstance();
		s.say();
	}
}

 

评论
发表评论

您还没有登录,请登录后发表评论

zwm
搜索本博客
博客分类
最近加入圈子
存档
最新评论