Page 1 of 1

Singleton Pattern

Posted: Sat Apr 19, 2008 1:27 am
by dejai
Have you implemented the Singleton Pattern in your framework?

Posted: Sat Apr 19, 2008 1:28 am
by Falco Girgis
Yeah, MarauderIIC and I use singletons for almost every system in the engine.

Posted: Sat Apr 19, 2008 1:40 am
by Orgodemirk
I use singletons in the framework for my perl scripts.

Posted: Sat Apr 19, 2008 1:50 am
by Falco Girgis
Peter, you also use singletons in lua.

:guffaw:

Posted: Sat Apr 19, 2008 7:17 am
by dejai
nice :D

Bad practise?

Posted: Wed May 07, 2008 9:02 pm
by kilgariff
I've heard a lot of people say that singletons aren't necessary, and the use of a singleton could be replaced, but I don't really know why someone would want to do so with no benefit to performance, clarity, or development time.

Posted: Wed May 07, 2008 9:42 pm
by MarauderIIC
You can pass stuff around like a hot potato but it gets really complicated. Did you perhaps hear what to replace it with? I'm interested in any programming theory around. =)

Posted: Thu May 08, 2008 10:42 pm
by kilgariff
MarauderIIC wrote:You can pass stuff around like a hot potato but it gets really complicated. Did you perhaps hear what to replace it with? I'm interested in any programming theory around. =)
Effectively just a sugar-coated version of slinging a pointer around.
The article and sub-article I read detailed everything that made singleton an "anti-pattern", but didn't suggest a better solution for that situation.

By the way, what do you use to implement singletons? I use a static instance that's initialized lazily. I'm going to thread my engine soon, and I don't think this is an *ideal* solution.

(PS. I tried to find the site that detailed everything wrong with the pattern, but I can't find it. If it's important, I could spend a little while retracing my steps.)