Why are singleton objects more object-oriented?

后端 未结 7 2163
心在旅途
心在旅途 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:06

    Hint: it's called object-oriented programming.

    Seriously.

    Maybe I am missing something fundamentally important, but I don't see what the fuss is all about: objects are more object-oriented than non-objects because they are objects. Does that really need an explanation?

    Note: Although it sure sounds that way, I am really not trying to sound smug here. I have looked at all the other answers and I found them terribly confusing. To me, it's kind of obvious that objects and methods are more object-oriented than namespaces and procedures (which is what static "methods" really are) by the very definition of "object-oriented".

    An alternative to having singleton objects would be to make classes themselves objects, as e.g. Ruby, Python, Smalltalk, Newspeak do.

提交回复
热议问题