Singleton Class design Issues
This question already has an answer here:
If it was public, everybody could use Singleton.instance
and would complain because it's null. Making it private forces them to use getInstance()
, which guarantees to return a non-null instance.
If it wasn't static, it would be an instance variable of Singleton, and you would thus need a Singleton instance to access the unique Singleton instance which doesn't make much sense.
链接地址: http://www.djcxy.com/p/82172.html上一篇: 单身人士有什么不好?
下一篇: Singleton类设计问题