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?
what is message passing in OO?
java;c#;c++;object oriented
What is message passing? (Can someone give a practical example?)Message passing simply means that (at a very abstract level) the fundamental mechanism of program execution is objects sending each other messages. The important point is that the name and structure of these messages is not necessarily fixed beforehand in the source code and can itself be additional information. This is an important part of what Alan Kay originally envisioned as object oriented programming.Is there any support for this message passing in C++, C# or Java?These language implement a limited version of message passing through method calls. Limited because the set of messages that can be sent is limited to the methods declared in a class. The advantage of this approach is that it can be implemented very efficiently, and it enables very detailed static code analysis (which results in all kinds of useful benefits, like code completion).Conversely, languages that implment real message passing often have method definitions too, as a convenient way to implement message handlers, but allow classes to implement more flexible message handlers that enable the object to recieve method calls with arbitrary names (not fixed at compile time).An example in Groovy that demonstrates the power of this concept: def xml = new MarkupBuilder(writer)xml.records() {  car(name:'HSV Maloo', make:'Holden', year:2006) {    country('Australia')    record(type:'speed', 'Production Pickup Truck with speed of 271kph')  }}will produce this XML:<records>  <car name='HSV Maloo' make='Holden' year='2006'>    <country>Australia</country>    <record type='speed'>Production Pickup Truck with speed of 271kph</record>  </car></records>Note that records, car, country and record are syntactically method calls, but there are no methods of that name defined in MarkupBuilder. Instead, it has a catchall message handler that accepts all messages and interprets the message names as the name of an XML element, parameters as attributes and closures as child elements.