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
		- 
				
				 turbod3006yResponse: "A heavy metal band. Have you ever been on one of their concerts? They are amazing!" turbod3006yResponse: "A heavy metal band. Have you ever been on one of their concerts? They are amazing!"
- 
				
				@Humanoid- you dont know the situation, I assumed he got told to make something in a singleton pattern and then asked what it was.
 
 If he did see it somewhere else I would have told him to look it up even though explaining it right away is way quicker.
- 
				
				@Humanoid- @Codex404 I told him that one of the classes is a Singleton, so he could store some value in a class property and it will be accessible in all other classes that this service is injected
- 
				
				What's wrong with that? Singleton's aren't nearly as used a pattern as they were, say 10 years ago. Many people would go as far as to consider them a code smell. It's not a given that he'd know what one is.
 
 I wish I had people working under me who asked questions like this, rather than just assuming they can guess at the answer and plough ahead with implementing bollocks.
- 
				
				@Humanoid- if it comes up during conversation I prefer you ask me right away, otherwise everything of the conversation after that is half clear and within 30 seconds it can be explained in a matter you need to understand what I am saying.
- 
				
				Be glad he asked. And not knowing what a Singelton is... Is actually a good thing!
- 
				
				This is still far better than what one of my director asked.
 What is the difference between a portal & cloud.
- 
				
				
- 
				
				@IntrusionCM In fairness, while I generally go for "A class that can only ever be instantiated once", the *accepted definition* can vary somewhat between languages.
- 
				
				@AlmondSauce Singleton is one of the most basic design patterns....
 
 And language support shouldn't be a problem.
 
 The description you gave is not complete nor totally wrong.
 
 "Store some value in a class property and it will be accessible in all other classes that this service is injected"
 
 And that is completely wrong.
 
 A singleton can only be created once - yes, but - and that's the reason why singleton's are considered an anti pattern - the instance can be accessed globally.
 
 Usually a singleton is self creating.
 
 A service, especially when injecting in DI sense, shouldn't be a singleton.
 
 Very unsure what the author meant, could be from value object to static variable, but a singleton makes no sense...
 
 (In case a service is created that has an property that is an singleton and is passed around... Ouch. That's fuckity. Really.)
- 
				
				@IntrusionCM The description I gave isn't wrong at all (excluding some weird classless singleton type hacks), and is about as complete as you can get in a general sense.
 
 Language *support* generally isn't an issue (though it's definitely harder in some languages than others), but whether a singleton is self-creating, is a service, is a driver wrapper, is instantiated eagerly or lazily, or heck, is even based off a class at all, can vary between languages & implementations.
 
 Your assertion that it can be always accessed globally is also not correct - I've seen plenty of package level singletons.
Related Rants








 when your code is a mess but everything work out in the end
when your code is a mess but everything work out in the end
 When you keep getting +1s on a rant you posted a month ago.
When you keep getting +1s on a rant you posted a month ago.
 Go big or go home.
Go big or go home.
Last Friday a coworker asked me what a Singleton is.
He graduated 3 years ago.
I think we have to improve our hiring process.
rant
sadness is coming
coworker
singleton