CS3340:   Intro OOP and Design

 

What is a Message?

They are used by software objects to communicate with other software objects.

Object A: the Transmitter

Object B: the Receiver

Sometimes, the receiving object needs more information so that it knows exactly what to do; for example, when you want to change gears on your bicycle, you have to indicate which gear you want. This information is passed along with the message as arguments or parameters. The next figure shows the three components that comprise a message:

  1. The object to which the message is addressed (YourBicycle)
  2. The name of the method to perform (changeGears)
  3. Any arguments/parameters needed by the method (lowerGear)

Messages provide two important benefits:

  • An object's behavior is expressed through its methods, so (aside from direct variable access) message passing supports all possible interactions between objects.
  • Objects don't need to be in the same process or even on the same machine to send and receive messages back and forth to each other.


Difference between Messages & Proceedure Calls

1) Message has a receiver (an object to which message is sent)

2) Interpretation of message is up to receiver.




In Java, C++: Messages passing is implemented via invokation of an object's methods.

 

Some Issues

How to access Reciever from within a method:

 

In Java and C++: Use the predefined variable "this" which refers to the object itself.

 

class Dog {

public Feed(String food, float ammount) {

this.stomachfull = ammount; }

}

 

 

 

© Lynne Grewe