Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The top answer is basically saying:

1. The "Gang of Four" "Singleton" pattern, meaning stateful functionality that is statically available from anywhere, is broken. It hides dependencies and makes it impossible to uncouple the items for testing.

2. However, the idea of an application needing a single instance of an object, whether it be a configuration or renderer or what-have-you, is quite common.

3. Using "dependency injection" allows use of single instances, without the "Singleton" pattern. Which, to clarify, does not necessarily mean the more magical forms of dependency injection found in systems such as Spring, where you simply declare a variable and it is magically fulfilled later. It can also just be a parameter in the constructor of the dependent object.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: