By bloid
via sitepoint.com
Published: Feb 15 2008 / 11:13
It’s a good question, for it is true that global variables are often demonised and more recently the Singleton has befallen the same fate. Perhaps a bit surprising, it is remarkably hard to find good arguments to support this common knowledge — Googling turns up a lot of confusion.
Comments
daniel replied ago:
I think his conclusion is absolutely wrong, but it's a good article. Singletons (properly applied) are a way to *reduce* coupling, not increase it. Global state is a fact of life in imperative languages. Unless you want to write things completely functionally, you will have to deal with side-effects at some point. Using global state wrapped within a singleton gives you a way to mitigate the consequences of such side-effects and avoid code duplication.
dzonelurker replied ago:
Rather, global state is a fact of life for inexperienced programmers. There is no inherent necessity for global state.
willcode4beer replied ago:
Hasn't the singleton horse been beat to death and then some already?
Voters For This Link (10)
Voters Against This Link (5)