Skip to content

pitfalls

Singleton implementation pitfalls

In this blog I want to show implementation pitfalls of the singleton pattern and show you why enums are the better singletons. The singleton pattern is widely known and discussed a lot of times. Developers often prefer to implement a singleton using a final static field. But this approach has some pitfalls or rather malicious code can compromise the singleton pattern. In the next sections I will show you the possible attacks on singleton implementations that compromise the pattern. Maybe you will use this techniques to implement a kind of workaround some day, but I hope you will not. Static Final Field Singleton The purpose of a singleton is that only 1 instance of a… Read More »Singleton implementation pitfalls

GDPR Cookie Consent with Real Cookie Banner