[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
Singleton
Singleton: A class of which only a single instance can exist. Ensure a class only has one instance, and provide a global point of access to it.
Don’t need fig, just remember implementation.
One class, two static,
three access levels(private, protect, public)
class
Singleton
{
private
:
static
Singleton
*
m_instance
;
protect
Singleton
();
public
:
static
getInstance
();
}
Singleton
*
Singleton
::
m_instance
=
nullptr
;
Singleton
::
getInstance
(){
if
(
m_instance
==
nullptr
)
m_instance
=
new
Singleton
();
return
m_instance
;
}
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]