Code Smell 32 - Singletons

Code Smell 32 - Singletons

Maxi Contieri
·Nov 23, 2020·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

The most used and (in)famous design pattern in the world is causing us great harm.


  • Coupling

  • Testability.

  • Accidental implementation problems.

  • Multi threading issues.

  • Static methods polluting.

  • Object creation contract violation.

  • Bijection mismatch.

  • Memory issues.

  • Premature Optimization.


  1. Avoid it.

  2. Use contextual unique objects.

  3. Benchmark object creation.


  • Database Access

  • Globals

  • Loggers

  • Helpers

Sample Code


God is the archetypical singleton example.


This is a design pattern. We should avoid it by policy.

We can add linter rules for patterns like 'getInstance()' so new developers cannot infect code with this anti-pattern.


  • Globals


This is an historical mistake already acknowledged by the community. Nevertheless, lazy developers bring it again and again. We need to reach a consensus on its drawbacks.


More info


Photo by Maria Teneva on Unsplash

The Diagram is Not the Model. The model is not the diagram. It is an abstraction, a set of concepts and relationships between them.

Eric Evans

This article is part of the CodeSmell Series.

Share this


Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)