`
linzhanghui
  • 浏览: 45452 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

常用设计模式

    博客分类:
  • Java
阅读更多

单例模式

   简单描述:确保一个类只有一个实例,并提供一个全局访问点

 

package com.linzhanghui.designpatterns;

public class Singleton {
	private static Singleton uniqueInstance;

	private Singleton() {
	}

	public static Singleton getInstance() {
		if (uniqueInstance == null) {
			uniqueInstance = new Singleton();
		}
		return uniqueInstance;
	}
}

 

常见应用场景:

 

 

工厂模式:

常见应用场景:

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics