当前位置:网站首页>[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
边栏推荐
- Repetition is the mother of skill
- Ctfshow permission maintenance
- One revolution, two forces and three links: the "carbon reduction" road map behind the industrial energy efficiency improvement action plan
- MaxPool2d详解--在数组和图像中的应用
- Operation record of reinitialization instance of Dameng database
- 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
- Flitter - sort list sort
- Lombok
- Ctfshow framework reproduction
- Mysql database query optimization
猜你喜欢

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

Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance

Software supply chain security risk pointing North for enterprise digitalization and it executives

MaxPool2d详解--在数组和图像中的应用

企业出海数字化转型解决方案介绍

To tell you the truth, ThreadLocal is really not an advanced thing

Zero sample and small sample learning

One revolution, two forces and three links: the "carbon reduction" road map behind the industrial energy efficiency improvement action plan

In depth understanding of jetpack compose kernel: slottable system

Esp8266 becomes client and server
随机推荐
Swift 5.0 - creation and use of swift framework
Code de conduite pour la vente de fonds et la gestion de l'information
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
To tell you the truth, ThreadLocal is really not an advanced thing
Qt笔记(七十四)之QLineEdit指定输入类型
如何使用 DataAnt 监控 Apache APISIX
Flitter - sort list sort
Sm2246en+ SanDisk 15131
ABAQUS 2022 latest edition - perfect realistic simulation solution
Kubevela 1.4: make application delivery safer, easier to use, and more transparent
MIT doctoral dissertation optimization theory and machine learning practice
35 giant technology companies jointly form the meta universe standard Forum Organization
What does it mean to open an account online? Is it safe to open an account online?
Fund sales code of conduct and information management
让企业数字化砸锅和IT主管背锅的软件供应链安全风险指北
Qlineedit of QT notes (74) specifies the input type
Detailed explanation of conv2d -- use in arrays and images
Wordpress blog uses volcano engine veimagex for static resource CDN acceleration (free)
C# /platform:anycpu32bitpreferred 只能与 /t:exe、/t:winexe 和 /t:appcontainerexe 一起使用
Development of wireless U-shaped ultrasonic electric toothbrush