Which design pattern is used to ensure a class has only one instance and provides a global point of access to it?

  • Factory
  • Observer
  • Singleton
  • Strategy
The design pattern used to ensure a class has only one instance and provides a global point of access to it is the Singleton pattern. This pattern restricts instantiation of a class to a single object and provides a way to access that instance globally. It is commonly used in scenarios such as database connections, logging mechanisms, and configuration settings where having multiple instances can lead to issues like resource wastage or inconsistent behavior.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *