当前位置:网站首页>[designmode] singleton pattern
[designmode] singleton pattern
2022-06-30 23:46:00 【weixin_ forty-three million two hundred and twenty-four thousan】
1. Introduction to singleton design patterns
So called class singleton design pattern , Is to take certain methods to ensure that in the whole software system , There can only be one object instance for a class , And this class only provides a method to get its object instance ( Static methods ).
such as Hibernate Of SessionFactory, It acts as a proxy for the datastore source , And responsible for creating Session object .SessionFactory It's not lightweight , In general , A project usually only needs one SessionFactory Is enough , This will be used in singleton mode .
2. There are eight ways to design singleton
There are eight ways of singleton mode :
1) Hungry Chinese style ( static const )
2) Hungry Chinese style ( Static code block )
Slacker type ( Thread unsafe )
Slacker type ( Thread safety , Synchronization method )
Slacker type ( Thread safety , Synchronization code block )
6) Double check
7) Static inner class
8) enumeration
3. Hungry Chinese style ( static const )
Hungry Chinese style ( static const ) Application example
Steps are as follows : Silicon Valley Java Design patterns
Constructor privatization ( prevent new )
Create objects inside the class
Expose a static public method .getInstance
Code implementation
边栏推荐
- leetcode 474. Ones and zeroes (medium)
- CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
- C /platform:anycpu32bitpererrored can only be used with /t:exe, /t:winexe and /t:appcontainerexe
- Analysis of 8253a register
- LVM snapshot: preparation of backup based on LVM snapshot
- ABAQUS 2022 software installation package and installation tutorial
- Shell multitasking to download video at the same time
- Fund managers' corporate governance and risk management
- 如何区分平台安全和网上炒作?网络投机有哪些止损技巧?
- Fund clients and sales agencies
猜你喜欢

Maxpool2d explanation -- Application in arrays and images

Redis - 01 cache: how to use read cache to improve system performance?

HP notebook disable touchpad after mouse is inserted

Prospects of world digitalization and machine intelligence in the next decade

Solve arm_ release_ ver of this libmali is ‘g2p0-01eac0‘,rk_ so_ Ver is' 4 ', libgl1 mesa dev will not be installed, and there are unsatisfied dependencies

Netease cloud sign in lottery? That year I could sign in for 365 days. No? Look.

The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?

唯一性索引与逻辑删除冲突问题解决思路
![CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构](/img/ce/519778cd731f814ad111d1e37abd10.png)
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构

Zero sample and small sample learning
随机推荐
shell 同时执行多任务下载视频
The college entrance examination in 2022 is over. Does anyone really think programmers don't need to study after work?
LVM snapshot: preparation of backup based on LVM snapshot
Redis - 01 cache: how to use read cache to improve system performance?
leetcode 474. Ones and Zeroes 一和零(中等)
What does project management really manage?
MIT doctoral dissertation optimization theory and machine learning practice
Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
Bridge emqx cloud data to AWS IOT through the public network
Query points in MATLAB Delaunay triangulation
Advanced mathematical modeling
未来十年世界数字化与机器智能展望
What does it mean to open an account online? Is it safe to open an account online?
When we look at the industrial Internet, we always look at it from the opposite of the consumer Internet
企业出海数字化转型解决方案介绍
Shell multitasking to download video at the same time
需求评审,测试人员应该发挥怎样的价值?两分钟让你不再懵逼
How do it outsourcing resident personnel position their pain points?
五分钟搞懂探索式测试
Schéma de transition asynchrone - générateur