SlideShare a Scribd company logo
Design pattern  singlestone
Design pattern  singlestone
I have a problem with my
system design, I want
restrict the instantiation of
the database connection to
one instance only
I want to prevent clients to
create more than one
database connection.
( Restrict Instances )
Heap
getDBInstance()
openConnection()
openConnection()
openConnection()
Thread
Thread
Thread
Stack
What is singleton pattern ?
• A class has only one instance in memory
• Initialization only will be at first use
• Provide a global point or single point to access the class
• Clients cannot create a new instance directly with new keyword
• This type of design pattern comes under creational patter
Singleton Pattern Implementation
• Ensure that Class constructor is private to prevent create new instance
directly
• Define a private static attribute in class to instantiates an only instance at
first time
• Define static method that returns the instance of the class
• Clients may only use the Accessor function to manipulate the Singleton
Design pattern  singlestone

More Related Content

PDF
Factory and Class Cluster
PPTX
Introduction to OOP with java
PPTX
The Singleton Pattern Presentation
PPTX
Singleton Design Pattern - Creation Pattern
PPTX
Singleton Pattern (Sole Object with Global Access)
PPTX
Singleton Pattern
PPTX
Invoke component
PPTX
Java component
Factory and Class Cluster
Introduction to OOP with java
The Singleton Pattern Presentation
Singleton Design Pattern - Creation Pattern
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern
Invoke component
Java component

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Lesson notes of climatology university.
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
human mycosis Human fungal infections are called human mycosis..pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Microbial disease of the cardiovascular and lymphatic systems
Final Presentation General Medicine 03-08-2024.pptx
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
Weekly quiz Compilation Jan -July 25.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Lesson notes of climatology university.
Ad
Ad

Design pattern singlestone

  • 3. I have a problem with my system design, I want restrict the instantiation of the database connection to one instance only I want to prevent clients to create more than one database connection. ( Restrict Instances )
  • 5. What is singleton pattern ? • A class has only one instance in memory • Initialization only will be at first use • Provide a global point or single point to access the class • Clients cannot create a new instance directly with new keyword • This type of design pattern comes under creational patter
  • 6. Singleton Pattern Implementation • Ensure that Class constructor is private to prevent create new instance directly • Define a private static attribute in class to instantiates an only instance at first time • Define static method that returns the instance of the class • Clients may only use the Accessor function to manipulate the Singleton