php、java实现单例模式
来源:互联网 发布:21天学通c语言百度云 编辑:程序博客网 时间:2024/04/29 11:25
一、java实现的三种方式
方式一
public class SingleInstance { private static final SingleInstance instance = new SingleInstance(); private SingleInstance(){} public SingleInstance getInstance(){ return instance; }}
方式二
public class SingleInstance { private SingleInstance(){} public SingleInstance getInstance(){ return SingleInstanceFactory.instance; } private static class SingleInstanceFactory{ private static final SingleInstance instance = new SingleInstance(); }}
方式三
public class SingleInstance { private static SingleInstance instance = null; private SingleInstance(){} public static SingleInstance getInstance(){ if(instance == null){ synchronized (SingleInstance.class){ if(instance == null){ instance = new SingleInstance(); } } } return instance; }}
二、php方式
class SingleInstance{ private function __construct(){ echo "11111"; } public static function getInstance() { static $instance; if(false == $instance) { $instance = new self(); } return $instance; } }
0 0
- php、java实现单例模式
- php实现单例模式
- PHP实现单例模式
- PHP实现单例模式
- PHP 单例模式实现
- PHP实现单例模式(单态模式)
- 单例模式 java 实现
- 单例模式--java实现
- java 实现单例模式
- java实现单例模式
- java 实现单例模式
- Java实现单例模式
- Java 实现单例模式
- java实现单例模式
- java 实现单例模式
- java实现单例模式
- java实现单例模式
- Java实现单例模式
- 新手如何学习c语言
- C++建模实战1-高考录取系统(2)
- PAT(A)-1123. Is It a Complete AVL Tree (30)(AVL+bfs)
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- L2-016. 愿天下有情人都是失散多年的兄妹
- php、java实现单例模式
- 链表刷题总结-技巧以及注意事项
- HDU-1532 Drainage Ditches,人生第一道网络流!
- java的数学运算
- Uva-1627 Team them up!(背包变形)
- 虚析构函数
- C++ SSE运算例子
- 第二次作业
- 腾讯云服务器申请SSL证书, 配置Nginx, 实现HTTPS