Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
José Guerrero
6,195 PointsAdvantages and disadvantages of singletons in Java.
I'm new in this and it gets really dificultr to understand when should I use them and when I shouldn't.
1 Answer
Evan Demaris
64,262 PointsHi Jose,
Singletons are generally frowned upon as they violate the single responsibility principle, are a global instance, and defy encapsulation, among other issues. Knowing how to work with Singletons is good, because you will encounter them, but many, many developers believe they should never be used because of the previous arguments (among many others).
Hope that helps!
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsAlexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsI just wanted to add to this answer, that "Singleton" is also one of so-called Design Patterns.
Craig has an introduction to Design Patterns in this course:
https://teamtreehouse.com/library/introduction-to-design-patterns
And he talks a bit about "Singleton" in this video
https://teamtreehouse.com/library/creational
Make sure you check his teacher's notes. He always puts nice info about the course there