You are asked to create an object that should be instantiated only once and reused in other instances. Which design pattern would you implement?

  • Singleton Pattern
  • Factory Pattern
  • Observer Pattern
  • Prototype Pattern
In this scenario, you would implement the Singleton Pattern. The Singleton Pattern ensures that a class has only one instance and provides a global point of access to that instance. It's useful when you need to maintain a single instance of an object that is shared across multiple parts of your application. This can help in scenarios such as creating a global configuration or managing a resource pool.
Add your answer
Loading...