Junior — Middle
Have you used the Singleton pattern in your projects?
sobes.tech AI
Answer from AI
Yes, the Singleton pattern is often used to ensure a single instance of a class in an application, for example, to manage configuration, logging, or database access.
Example in Python:
class Singleton:
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
# Usage
s1 = Singleton()
s2 = Singleton()
print(s1 is s2) # True
In QA automation, Singleton can be used to create a single browser driver object to avoid unnecessary initializations.