Skip to main content
Bluecoders
← Tech glossary

Singleton

Term

Singleton = the one-of-a-kind object

The Singleton is a design pattern that ensures a class has only one instance across the whole program and provides a global access point to it. It is one of the patterns described in the reference "Gang of Four" book (1994).

It is used for resources that must remain unique: application configuration, a shared database connection, an event log (logger). In practice, the class constructor is made inaccessible and a method always returns the same instance, created on the first call.

The Singleton is also one of the most criticized patterns: it creates hidden global state, makes testing harder and tightly couples code. Many teams prefer dependency injection, which achieves the same result more explicitly.

Why it matters when hiring

The Singleton is a classic interview question. The good signal is not knowing how to code it, but knowing why it causes problems (testing, global state, concurrency) and what to replace it with. A candidate who presents it as a best practice without nuance probably has a mostly theoretical knowledge of design patterns.

A recruitment need?

Describe what you need. A recruiter from your sector will call you back.