| 503 | 23 | 27 |
| 下载次数 | 被引频次 | 阅读次数 |
单例设计模式能够保证某个类的对象在内存中只有唯一的实例,该实例易于被外界访问并节约系统资源。分析了单例模式的角色构成和创建要点,分别从饿汉式、懒汉式、双重验证式、类加载式、枚举式等5个方面阐述了单例模式的实现过程,总结了5种形式的优缺点和应用场景。将单例模式应用到JDBC数据库开发中,设计了一个JDBC工具类,为单例模式的实际应用提供了一定的参考。
Abstract:The singleton design pattern ensures that one class has only one object instance in memory,the instance is easy to be accessed by the outside world and save system resources.The role composition and the key points of the singleton pattern are analyzed,the implementation process of the singleton pattern is described from five aspects of hungry type,lazy type,double authentication type,class loading type and enumeration type.Then it summarizes the advantages and disadvantages of those five types,and their application scenarios.The singleton pattern is applied to the database development with JDBC,and a JDBC tool class is designed.It provides a reference for the practical application of the singleton pattern.
[1]陈烽,陈蓉,王跟成,孙懿.设计模式在区域综合管网中的应用研究[J].计算机技术与发展,2015,25(4):193-196.
[2]刘伟.设计模式[M].北京:清华大学出版社,2011:92-103.
[3]欧阳宏基,葛萌,赵蔷.基于JDBC与设计模式的数据库连接池实现方法[J].计算机技术与发展,2011,21(1):84-87.
[4]夏浩波.单例模式的设计与应用[J].电脑开发与应用,2011,24(1):58-59.
[5]张磊杰,刘永久,王慧.基于虚拟现实的步态训练康复机器人系统软件设计[J].计算机系统应用,2012,21(12):8-11.
[6]陈天超.单例设计模式研究[J].福建电脑,2016,(8):14-16.
[7]欧阳宏基,葛萌,陈伟.基于JDBC的数据持久化层性能优化研究[J].网络新媒体技术,2016,5(5):9-15.
基本信息:
中图分类号:TP311.52
引用信息:
[1]葛萌,欧阳宏基,陈伟.单例设计模式的研究与实现[J].微型电脑应用,2017,33(09):68-70+74.
基金信息:
咸阳师范学院专项科研计划项目(2014XSYK038)
2017-09-20
2017-09-20