views:

612

answers:

3

What is the example of the OOP concept 'Message Passing' in C# (calling methods/Passing parameters/Firing Events/Handling Events/???) and why is it called message passing?

+3  A: 

Method calls.

It's called message passing to distinguish it from the imperative notion of "calling a function", and to reinforce the idea that the receiving object decides what to do. On the call site, you just tell the receiver the "message".

Sii
A: 

It is called message passing to distinguish it from passing parameters.

A major benefit of passing a message is that you can change the contents of the message without changing the signature of the method recieving the message.

Another is that several methods may need the same information, it can therefore be defined and changed in the same place.

Shiraz Bhaiji
I appreciate your answer. But Sii's answer is clearer.
A: 

There are some who feel that message passing and method calls are different. We use the term interchangeably, but the meaning is subtle.

In smalltalk, message passing was run time bound, and the object had a way to determine if it could handle a message that wasn't explicitly defined as a method. Ruby calls this method_missing. Methods in C++ in particular are bound at compile time, with no way to dynamically add ways to handle more messages. C# 4.0 has a mix, once you start throwing dynamics around.

There's another school of message passing, Erlang believes all message arguments need to be decoupled in state. That is, they are either immutable or copies.

Ball
I've heard the latter definition quite a bit--that messages are decoupled method calls that can be multi-threaded or processed off the machine. In languages like C++ and Java this functionality doesn't exist so the terms tend to be synonymous.
Bill K