Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Python:** Override __new__; return cached instance. Java: private constructor, static getInstance(), synchronized (or volatile+double-check) for thread-safety. **Trade-off:** Singleton = global state, hard to test. Prefer dependency injection....
Python: Override __new__; return cached instance. Java: private constructor, static getInstance(), synchronized (or volatile+double-check) for thread-safety.
Trade-off: Singleton = global state, hard to test. Prefer dependency injection. Use for: connection pools, config loaders—single shared resource.
class Singleton:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
Red Flag: Singleton for everything. Pro-Move: 'We use Singleton only for DB connection pool—inject in tests with mock.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.