Design Patterns: Thoughts on the Singleton Pattern(honestillusion.com)

submitted by JamesCurranJamesCurran(635) 5 years, 2 months ago

Thoughts on the Singleton Pattern (Executive summary: Don't!)

5 comments |category: |Views: 5

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by yesthatmcgurkyesthatmcgurk(4063) 5 years, 2 months ago 0

"Don't use a singleton."
"Why?"
"They're pretty much the same as global variables and static classes. Use those instead."
"Well, if they're pretty much the same, then why not use a singleton?"
"..."

Also: Author notes he fixed some spelling and "grammer" problems.

Reply

posted by yesthatmcgurkyesthatmcgurk(4063) 5 years, 2 months ago 0

For extra lulz, here's the author and submitter: http://honestillusion.com/photos/rnc/picture2650.aspx

Reply

posted by JamesCurranJamesCurran(635) 5 years, 2 months ago 0

Actually, that isn't me, but a friend of mine (I took the picture)

And I do say why to not use a singleton: " If you are going to have to deal with all those problems anyway, you might as well choose the method which is both the most easily understood, most efficient, and requires the least typing."

Reply

posted by photozphotoz(80) 5 years, 2 months ago 0

I'm using a singleton as a memory store for a collection of objects that are constructed from the database.
This is used in a web app. The singleton pattern provides a nice way to store a singular set of data that is loaded from the DB once without having to continually hit the DB for accessing the same information.

Singleton has a purpose and it serves itself well in the web app model.

Reply

posted by aabsaabs(850) 5 years, 2 months ago 0

Unless you are using your singleton with great care in the web app area, you will find that it does anything but serve well.

http://aabs.wordpress.com/2007/03/08/singleton-%e2%80%93-the-most-overused-pattern/

think twice before you opt for singleton. And if after you thought twice you still mean to use it - make it bullet-proof. Then come back and tell us if the effort was worth it to use the pattern.

Reply

information Login or create an account to comment on this story