学习设计模式-单列模式
来源:互联网 发布:linux服务器占有率 编辑:程序博客网 时间:2024/06/04 19:04
package com.pattern.create.singleton;
/**
* 单列模式
*
* @author OF
* @date 2016年8月18日
*/
public class Singleton {
/**
* 赖汉式
*/
private static Singleton s = null;
/**
* 构造方法静态化
*/
private Singleton() {
super();
}
public static Singleton getInstance() {
if (s == null) {
return new Singleton();
}
return s;
}
/**
* 饿汉式
*/
private static Singleton Singleton = new Singleton();
public static Singleton getSingleton() {
return Singleton;
}
public void show() {
System.out.println("123333");
}
public static void main(String[] args) {
@SuppressWarnings("static-access")
Singleton s = Singleton.getSingleton();
s.show();
}
}
/**
* 单列模式
*
* @author OF
* @date 2016年8月18日
*/
public class Singleton {
/**
* 赖汉式
*/
private static Singleton s = null;
/**
* 构造方法静态化
*/
private Singleton() {
super();
}
public static Singleton getInstance() {
if (s == null) {
return new Singleton();
}
return s;
}
/**
* 饿汉式
*/
private static Singleton Singleton = new Singleton();
public static Singleton getSingleton() {
return Singleton;
}
public void show() {
System.out.println("123333");
}
public static void main(String[] args) {
@SuppressWarnings("static-access")
Singleton s = Singleton.getSingleton();
s.show();
}
}
0 0
- 学习设计模式-单列模式
- 设计模式学习—单列模式
- 设计模式--单列模式
- 设计模式-单列模式
- 单列模式设计
- 设计模式之单列
- 单列设计模式
- android 设计模式:单列
- java单列设计模式
- 单列设计模式
- php单列设计模式
- 单列设计模式
- 温习设计模式单列
- 浅谈单列设计模式
- 单列设计模式
- Java单列设计模式
- 设计模式之单列模式
- 设计模式之单列模式
- Oracle日期与时间戳timestamp的转换
- java web 开发需要用到的技术
- C# BackgroundWorker的使用
- 屏蔽js类库加载的时候某个属性
- Android开发-ListView的使用
- 学习设计模式-单列模式
- 搭建ejabberd集群
- bzoj4034(树链剖分裸题)
- TCP 协议--详解--来源于两篇博客
- 2434: [Noi2011]阿狸的打字机
- Unity--关于Layer的问题
- 关于systemd的一点知识
- tensorflow debug c++ code
- 自定义雷达定位图(基于极坐标系)