Death of Singleton? Rise of Dependency Injection?

Was researching on the Singleton pattern and most articles on stack overflow were negative on the Singleton. link.  What I got out of the discussions is that it’s really bad for developers who do TDD (test driven development). In the words of the guys from article “They share all the problems globals have with hidden coupling (directly impacting testability and maintainability), and often the “only one can exist” restriction is actually a mistaken assumption.”

Instead of using singleton patterns, people are using Dependency Injection. Sounds pretty fancy but at it’s most basic it just mean passing in the ‘one’ object you need as an argument to the constructor. Link.

Other links:

Google Testing Blog: Dependency Injection

This entry was posted in Java and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s