I've been studying OO programming, primarily in C++, C# and Java. I thought I had a good grasp on it with my understanding of encapsulation, inheritance and polymorphism (as well as reading a lot of questions on this site).
One thing that seems to popup up here and there is the concept of 'message passing'. Apparently, this is something that is not used whilst OO programming in today's mainstream languages, but is supported by Smalltalk. My questions are: • What is message passing? (Can someone give a practical example?) • Is there any support for this 'message passing' in C++, C# or Java?
A member function call is one implementation of passing a message. The message passed is identified by the function name, and includes the information from the parameters. Late binding allows the receiving class to handle the same message in a different way to other classes. It's not what was intended by the creators of Simula, and many people would object to calling it message passing and state (with good reason) that doing message passing is a key thing that makes Simula different, but member function calls still do essentially the same job. – Mar 20 '12 at 12:42. Message passing is a different way of handling the need in OO code for one object to get another object (or potentially itself) to do something. In most modern languages that descend from the C++ approach we do that with method calls.
In this case the called object (via its class definition) puts a big list of what method calls it accepts and then the coder of the calling object simply write the the call: public void doSomething ( String input ). Other_object.dosomething ( local ) For statically typed languages then compiler can then check the type of the thing being called and confirm that the method has been declared. For dynamically typed languages then that is carried out at runtime.