Skip to main content
12 events
when toggle format what by license comment
Mar 15, 2024 at 16:41 comment added Chthonic One @KarlKnechtel To be honest, I haven't read the original book. I'm 47, but I never had the pleasure. While I've been programming since the 2nd grade, I didn't come into software development until after the military in 2010. Every example I can find seems to be written for, or makes reference to Java. I only assumed. So I guess, chalk it up to my inexperience there. Also, Java is the primary language my work deals with, and the government seems to accept from us.
Mar 15, 2024 at 9:25 comment added AnoE @KarlKnechtel, the book and Java came out at the same time, maybe even the same year IIRC. When I was just a wee software dev, somewhere around 2000 or so, I created a medium-size Java application for a business. I had freshly re-read the book and was really into it. I patterned the sh* out of that app! :) At the time, Java was the hot next thing in the business world, and we were all using patterns like there's no tomorrow. It was perfect. Well, if applying Design Patterns is your definition of perfection. Soooo many interfaces, soo much indirection. Thank bob, dev has matured since then.
Mar 15, 2024 at 7:10 comment added Karl Knechtel @ChthonicOne why the Java sphere? I recall the examples in the book being in C++ (Wikipedia says there were also Smalltalk examples).
Mar 14, 2024 at 17:46 comment added JacquesB @gnasher729: This is a general issue with globals, not just singletons. One benefit of dependency injections is that the dependencies of a class are explicit. If 50 different classes have a dependency on the same global, then you might have a bigger problem.
Mar 14, 2024 at 16:52 comment added gnasher729 Sorry, but if a singleton gives you problems with testing, then you are doing it wrong. If you consider replacing a singleton with dependency injection in 50 places, ask yourself how you would achieve the same with one dependency injection at most.
Mar 13, 2024 at 19:31 comment added Chthonic One @JaredSmith I believe it stems from the fact that certain people believe that everyone in the Java sphere must know these patterns, and since everyone knows them, some people interpret that as everyone must use them constantly. As a result they suffer from overuse. On top of it, some of them cause code obfuscation, testing difficulties, and other issues if not handled correctly. They can be good patterns if used correctly, but often they are not.
Mar 13, 2024 at 17:03 comment added Jared Smith Why "infamous" for the reference to GoF Design Patterns?
Mar 13, 2024 at 16:00 comment added Didier L @Caleb “If you just happen to have only one instance of an class, that's not a singleton”: that’s not a singleton pattern. That’s still a singleton though, and that’s how Spring singleton beans work (and they are the default). So (2) is not implied by (1), especially in the scope of DI.
Mar 13, 2024 at 15:52 comment added Voo @Caleb If you go by that definition, virtually no singleton in a container would be a singleton, because you could easily create more of them - it's just convention (in production code) to not do so. The ability to easily create more instances is also exactly what makes it useful for testing where you may want a "singleton" per test (with multiple tests running in parallel even).
Mar 13, 2024 at 15:29 vote accept Tyler Del Rosario
Mar 13, 2024 at 14:55 comment added Caleb Your first meaning should say: An object where only a single instance can exist. If you just happen to have only one instance of an class, that's not a singleton; the singleness needs to be enforced somehow. And since only being able to instantiate a class once implies a need for a way to get the one instance, (2) is strongly implied by (1).
Mar 13, 2024 at 6:43 history answered JacquesB CC BY-SA 4.0