当前位置:网站首页>07 singleton mode
07 singleton mode
2022-07-06 02:38:00 【zzyzxb】
The singleton pattern / Singlet mode : Create pattern , Create a class that produces only one object instance ---- Use private constructor to realize the definition of class .
One : Basic concept and implementation of singleton class
GameConfig,Scott Meyers“ Make the interface or type easy to use correctly , Difficult to misuse ”
Only one class belonging to this class can be created, which is called singleton class .
(2) Problems that a singleton class can cause in multithreading
A good solution to multithreading creation GameConfig The method of class object problem is in main Main function ( Program execution entry ), Before creating any other threads ,
Do it first GameConfig::getInstance(); Let's put this alone GameConfig Class object is created .
(3) Hungry and lazy
(4) Memory release problem of singleton class object
(5) Single piece class definition 、UML Figure and another implementation method
Single piece design pattern definition : Ensure that only one instance of a class exists , At the same time, it provides a global method that can access the instance (getInstance Member functions ).
Troubled problems : There are two problems in the cross reference between multiple singleton classes . Log、GameConfig—— Do not reference other singleton objects in the destructor of singleton class .
边栏推荐
- inherited constructors
- Bigder: I felt good about the 34/100 interview, but I didn't receive the admission
- Six stone management: why should leaders ignore product quality
- MySQL winter vacation self-study 2022 11 (6)
- Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
- 淘宝焦点图布局实战
- 事故指标统计
- 技术管理进阶——什么是管理者之体力、脑力、心力
- 3D drawing ()
- Black high-end responsive website dream weaving template (adaptive mobile terminal)
猜你喜欢
ReferenceError: primordials is not defined错误解决
RobotFramework入门(二)appUI自动化之app启动
力扣今日題-729. 我的日程安排錶 I
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
High number_ Vector algebra_ Unit vector_ Angle between vector and coordinate axis
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
A copy can also produce flowers
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Shell脚本更新存储过程到数据库
随机推荐
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
Keyword static
[robot library] awesome robots Libraries
从顶会论文看2022年推荐系统序列建模的趋势
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
inherited constructors
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
深度解析链动2+1模式,颠覆传统卖货思维?
Yyds dry inventory comparison of several database storage engines
Six stone management: why should leaders ignore product quality
MySQL winter vacation self-study 2022 11 (6)
[untitled] a query SQL execution process in the database
【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
Large scale DDoS attacks take Myanmar offline
模板_求排列逆序对_基于归并排序
GifCam v7.0 极简GIF动画录制工具中文单文件版