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

前端 未结 10 458
无人及你
无人及你 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:23

    They're referring to the fact that a client can invoke a method on a receiving object, and pass data to that object, but that object can decide autonomously what to do with that data, and maintain its own state as required.

    The client object can't manipulate the state of the receiving object directly. This is an advantage of encapsulation - the receiving object can enforce its own state independently and change its implementation without affecting how clients interact with it.

提交回复
热议问题