Android 设计模式
来源:互联网 发布:中世纪的生活 知乎 编辑:程序博客网 时间:2024/06/16 13:27
class Instance{
private Instance(){}
public static Instance getSelf(){
return new Instance();
}
}
//懒汉式
class LSingle{
private static Instance _instance = null;
private LSingle(){}
public static Instance getInstance(){
if(_instance==null){
synchronized(LSingle.class){
_instance = Instance.getSelf();
}
}
return _instance;
}
}
//饿汉式
class ESingle{
private static Instance _instance = Instance.getSelf();
private ESingle(){}
public static Instance getInstance(){
return _instance;
}
private Instance(){}
public static Instance getSelf(){
return new Instance();
}
}
//懒汉式
class LSingle{
private static Instance _instance = null;
private LSingle(){}
public static Instance getInstance(){
if(_instance==null){
synchronized(LSingle.class){
_instance = Instance.getSelf();
}
}
return _instance;
}
}
//饿汉式
class ESingle{
private static Instance _instance = Instance.getSelf();
private ESingle(){}
public static Instance getInstance(){
return _instance;
}
}
懒汉式:在第一次加载这个类的时候创建出这个对象。
饿汉式:在程序加载的时候创建出这个对象。
一般我们使用的懒汉式比较多,因为我们不知道是否能够用到这个对象。
0 0
- Android设计模式--适配器模式
- android设计模式--外观模式
- android设计模式-策略模式
- android设计模式-观察者模式
- android设计模式-工厂模式
- android设计模式-适配器模式
- android设计模式-组合模式
- android 设计模式 状态模式
- android 设计模式-组合模式
- Android 设计模式-----单利模式
- Android设计模式--观察者模式
- Android设计模式--适配器模式
- Android设计模式-适配器模式
- Android设计模式-适配器模式
- Android设计模式-常用模式
- [Android] 设计模式-策略模式
- Android设计模式--Builder模式
- Android设计模式-适配器模式
- Hbase 绑定多网卡的问题
- Zookeeper:Timeout while waiting for epoch from quorum解决方案
- CRT detected that the application wrote to memory after end of heap buffer
- SAP 人力资源工资配置项1---工资计算周期配置
- 微信公众账号开发项目小结(四)
- Android 设计模式
- php_mssql.dll下载,php_mssql.dll修复
- shell----if条件判断参数
- elasticsearch 作为服务来运行
- c# textbox 问题与注意
- 四种途径将HTML5 web应用变成android应用
- 在VS2010 C++中调试DLL工程的方法
- 《你必须知道的495个C语言问题》知识笔记及补充
- hdu 小明系列问题——小明序列