Skip to content

Instantly share code, notes, and snippets.

@schowdhury
Created August 5, 2014 19:50
Show Gist options
  • Save schowdhury/7f6a161cdb60daf1be2a to your computer and use it in GitHub Desktop.
Save schowdhury/7f6a161cdb60daf1be2a to your computer and use it in GitHub Desktop.
message passing
If your introduction to object-oriented programming was like mine, somewhere early on day 1 you learned about “message passing.” You were told that doing something like
account.deposit(50)
meant that you were sending the deposit message to the account object. Of course, if you were learning about a statically typed language, you soon figured out that account.deposit(50) was synonymous with calling the deposit method on the account object. The whole static typing system was there to make sure that the deposit method was there and was called. So by the end of day 1 of object-oriented programming, we all stopped talking about passing messages and started talking about calling methods.
The concept of message passing would make more sense if we could say account.deposit(50), and the BankAccount class was then free to do something else with the message besides simply calling the deposit method. Perhaps the BankAccount class could call some method other than deposit, or perhaps it could decide to do nothing. It turns out that this is all possible in Ruby.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment