Results 1 to 1 of 1
Dec 9, 2013, 01:30 #1
- Join Date
- Apr 2013
- 6 Post(s)
- 1 Thread(s)
Question about the Singleton Antipattern in Scala
Well I've known that Singleton is an Antipattern for quite a while now and I pretty much never use it in my application. However, after taking a brief tour of Scala I cant help but noticing that it supports Singleton at a different level, you can even create Singleton Object using its language structure. I wonder why Scala supports Singleton since it has been proved to be an Anti-pattern. Come to think about it, two major characteristics of Singleton are:
1. It exhibits global state or global behavior.
2. It allows only one object to be created for the very class.
The first characteristics is apparently evil, globals are always poor programming practice no matter whether you are an OO or procedural programmer. The second can be a bit controversial though, which leads to this question. Is Singleton an Anti-pattern because it's misused like global variable/object, or that the restriction on creating one and only one object is inherently bad? If the former is true, it may explain what Scala is trying to accomplish by making singleton objects that aint like Java's pseudo-globals. If the latter is true, however, there will be no valid justification for ever using Singleton. What do you think?