DEV Community

Cover image for Singleton Pattern
Francesco Ciulla
Francesco Ciulla

Posted on • Updated on

Singleton Pattern

Singleton Pattern

Single object instance

GitHub code :

Creational pattern

⚡️Problem (we need)

  • One configuration file, from different components
  • Always the same file
  • Guaranteed that there is only one file


  • Ensure a class only has one instance.
  • Provide a global point of access to it.

🔧 Apply

  • One instance of a class is required
  • It must be one access point
  • Need to manage object instances


  • Single point of access to the instance
  • Avoid global variables
  • Ability to subclass the singleton class
  • Configure the number of instances


  • State of the singleton must be shareable between program executions

🏆 Great for

  • Manage number of instances at runtime
  • Provide one single unique access

Alt Text

GitHub code :

Top comments (0)