How exactly do “Objects communicate with each other by passing messages”?

前端 未结 10 437
无人及你
无人及你 2021-01-30 17:34

In several introductory texts on Object-oriented programming, I\'ve come across the above statement.

From wikipedia, \"In OOP, each object is capable of receivi

10条回答
  •  北海茫月
    2021-01-30 18:27

    Not exactly an answer to your question, but a little digression about message dispatch vs. method invocation:

    The term message refers to the fact that you don't know which method will be invoked due to polymorphism. You ask an object to do something (hence the term message) and it acts accordingly. The term method invocation is misleading as it suggest you pick one exact method.

    The term message is also closer to the reality of dynamic language, where you could actually send a message that the object doesn't understand (see doesNotUnderstand in Smalltalk). You can then not really speak of method invocation given that there is none matching, and the message dispatch will fail. In static typed language, this problem is prevented.

提交回复
热议问题