Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@Mek101 i usually try to see if i can find any reason somebody might ever create two of a thing before deciding on a singleton. even if that reason is slightly contrived.
i know janet uses thread-local variables so avoid having to pass state variables around commonly as lua does. not a decision i'm super thrilled with at times but i get why calvin did it.
there's a lot of that you can design the singleton as though there could be more than one, and the add a facade that just communicates with the "default" instance of the class, which might even just be a thread local variable, since i think what people mostly want out of singletons is to primarily have everyone talk to the same object (with rare edge cases, like when you get in to a multi tenant scenario, where you might actually have some reason for having a second Application instance)