Search code examples
c#oopmessage-passing

OOP - Message Passing in C#


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?


Solution

  • 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".

    An example would be methods that are abstract in a class, and implemented in subclasses; or implementations of an interface method. When you call e.g. GetEnumerator() through a variable of type IEnumerable, you don't know at the call site what code should actually be executed.