Repaso
EspaƱol
Design & PracticesIntermediateDP-07

What is the main criticism of the Singleton pattern?

Options

  1. It uses too much memory for the single object that it keeps
  2. It adds hidden global state, so testing and parallelism get harder (Correct option)
  3. It cannot be implemented in some languages, such as Python
  4. It is always slower than a normal class in every case

Answer

It introduces hidden global state and makes testing and parallelism harder

Why

A Singleton guarantees there is only one instance of a class and lets everyone grab it from anywhere.

That is basically a global variable: code depends on it silently, tests share its state and interfere with each other, and it is hard to replace with a fake.

Prefer creating one instance at startup and passing it to whoever needs it (dependency injection).

Remember

Singleton = global state in disguise. Prefer injecting the instance.

Key terms

Practice this question in Repaso