'method' vs. 'message' vs. 'function' vs. '???'

后端 未结 11 843
北荒
北荒 2020-12-24 12:59

I recently asked a question about what I called \"method calls\". The answer referred to \"messages\". As a self-taught hobby programmer trying to phrase questions that don\

相关标签:
11条回答
  • 2020-12-24 13:55

    Message!=Method!=function

    in OOP different objects may have different methods bound to the same message.

    for example: the message "rotate left n degrees" would be implemented diffrently by diffrent objects such as shape, circle, rectangle and square.

    Messages: Objects communicate through messages.

    -Objects send and recieve messages.

    -the response to a message is executing a method.

    -the method to use is determine be the reciever at run-time.

    In C++ Methods and Messages are called function members.

    0 讨论(0)
  • 2020-12-24 13:55

    I'm not sure about origin of message terminology. Most ofter I encounter messages in UML design. Objects (Actors in UML terminology) can communicate with each other by means of messages. In real-world code message is just a function call usually. I think of message as of attempt to communicate with some object. It can be a real message (like messages in OS) or function calls.

    0 讨论(0)
  • 2020-12-24 13:58

    The "Message" term can refer to sending a message to an object, which is supported in some programming languages and not others.

    If the object supports the message, then it will execute some code. Otherwise it will just ignore it. This is a more dynamic approach than an explicit function/method call where the object must support that function.

    Objective-c, I believe, uses this messaging approach.

    0 讨论(0)
  • 2020-12-24 14:00

    In Object Oriented implementations like C#, the concept of a "message" does not really exist as an explicit language construct. You can't look at a particular bit of code and say "there's the message."

    Instead, a method of an object's class implies the idea that other objects can send a type of message which trigger the behaviour within that method. So you end up just specifying the method directly, rather than sending a message.

    With other implementations like Smalltalk, you can see the message being passed, and the receiving object has the ability to do with that message what it will.

    There are libraries which sit on top of languages such as C# which attempt to restore the explicit message passing feel to the language. I've been cooking up one of my own for fun here: http://collaborateframework.codeplex.com/

    0 讨论(0)
  • 2020-12-24 14:02

    method : similar to function in traditional languages

    message : similar to parameter passing in traditional language

    0 讨论(0)
提交回复
热议问题