Why are singleton objects more object-oriented?

后端 未结 7 2164
心在旅途
心在旅途 2020-11-29 04:38

In Programming in Scala: A Comprehensive Step-by-Step Guide, the author said:

One way in which Scala is more object-oriented than Java is that cla

7条回答
  •  鱼传尺愫
    2020-11-29 05:10

    Singleton objects behave like classes in that they can extend/implement other types.

    Can't do that in Java with just static classes -- it's pretty sugar over the Java singleton pattern with a getInstance that allows (at least) nicer namespaces/stable identifiers and hides the distinction.

提交回复
热议问题