Code Smell 32 - Singletons
The most used and (in)famous design pattern in the world is causing us great harm.
Accidental implementation problems.
Multi threading issues.
Static methods polluting.
Object creation contract violation.
Use contextual unique objects.
Benchmark object creation.
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.
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.
The Diagram is Not the Model. The model is not the diagram. It is an abstraction, a set of concepts and relationships between them.
This article is part of the CodeSmell Series.