ArjanCodes
16 minutes
The singleton pattern is a creational design pattern that restricts a class to a single shared instance, with a global access point. It is widely regarded as an anti-pattern because it introduces hidden global mutable state, invisible coupling, poor testability, and thread-safety hazards, and in Python a module already provides the single shared instance. The pattern's genuinely useful aspect is controlled instantiation, meaning that an expensive resource is created once and lazily on first use, which involves no shared state; the generalization is the object pool.