Breaking up with Singleton

Have you ever secretly come to really dislike someone?

 

At first you think they’re great. You might even want to get closer. Then, after spending time with them, you realize they are a little obnoxious. Then, bit by bit, you start avoiding them whenever you can.

Finally, the day comes, when a friend quietly whispers “You know, I can’t stand that person”.

Reaction: Relief

Suddenly you realize you’re not crazy, it isn’t you. It’s them. Really.

Well that day has come for me and the Singleton design pattern. In Steve Yegge’s Singleton Considered Stupid I found a friend to confirm my now near hatred for the so called singleton design pattern.

Singleton and I used to be close. When I first started seeing, and, I’ll admit it, using singleton I quickly began feeling a growing unease. I found myself callously using singleton to allocate an instance, and then never speaking to singleton or the instance again.

Then things went from bad to worse. Once I started testing singleton I noticed how self centered singleton was. How could someone insist that they always be “the only one”?

Finally I started cheating; using backhanded methods to use and discard whole series of singletons. I even always took care to keep each one ignorant of the other. I told myself it was just for “unit testing”, but I knew better.

Now I realize I can’t live like this. It’s over.

Now I will only be design patterns who don’t have to be the center of universe. No more cheating, no more lying.

I hope I never see another singleton again.

Leave a Reply

Your email address will not be published. Required fields are marked *