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

Java

Advantages 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.

I 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

1 Answer

Hi 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!