Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
dan-pud8588yUseful to know how they work and their purpose and how they can work with other patterns like factory. Scala does them natively with 'object' and makes them easy to use.
-
@kaqqao
The singleton pattern dictates that it provides global access to itself, what you're describing (and what IoC containers do) is not this.
People do not like the singleton pattern. It hides dependencies and makes testing far more difficult.
Having only one instance of an object in your application isn't a bad thing, I agree with you on that. -
like all things in programming, like factories, regexs, multiple inheritence, and singeltons: depends how you use them.
Overuse of a singelton, coupled with one or more of the mistakes above is a disaster for future maintenance of the codebase. Always make sure your usecase makes sense. -
@kaqqao
Yeah, the spring docs are great. They explain the difference between their singletons and the GoF singletons far better than I was about to try to!
Learning to use Singletons in Java. Then reading online that it might be an antipattern. Software Engineering ... 👌
undefined
java singleton