Singleton Design Pattern
The singleton design pattern is one of the Gangs of Four
design patterns, one of the simplest design patterns in Java, and belongs to the Creational Design Pattern
creational design pattern. It looks like a very simple design pattern, but when it comes to implementation, it brings up a lot of problems. Singleton Design Pattern
The implementation of the singleton design pattern in Java has always been a controversial topic.
Singleton Singleton
- The singleton pattern restricts the instantiation of a class, ensuring that only one instance of a class exists in the Java Virtual Machine.
- Singleton classes must provide a global access point to obtain instances of the class.
- The singleton pattern is used for logging, driver objects, caches, and thread pools.
- The singleton design pattern is also used in other design patterns like
Abstract Factory
,Builder
, ,Prototype
,Facade
etc. - The singleton design pattern is also used for Core Java classes such as
java.lang.Runtime
,java.awt.Desktop