a response back -- a message answer. A message answer is a returned value. It could be a number like 5, a character like ‘d’, or even a reference to an object.
Frog, kermit, the same colour as another instance of Frog, gribbit. Now what if we don’t know what colour gribbit is -- or better yet, we don’t need to know. We’re not interested whatsoever in the actual colour of gribbit or kermit. We just want to ensure they are the same colour.
be the colour of gribbit, which is returned as a message answer when we send gribbit the message getColour(). Imagine we have the colour of gribbit set to the variable x. Then you can see that the code we’d write to solve our problem would be: kermit.setColour(x) There’s no need to do this though. We can just use: kermit.setColour(gribbit.getColour())
send the message to the right of it to the receiver to the left of it. 1] The message getColour() is sent to gribbit. 2] gribbit returns a message answer of its colour. 3] This message answer supplies the argument of setColour(). 4] kermit is sent the message setColour() with this argument. So kermit now knows which colour to set itself to, and does so.
Frog object as its argument. For example: kermit.sameColourAs(gribbit) Although this message looks a little simpler on the surface, the actual code that makes it work is very similar to the example we just looked at. That is, kermit.sameColourAs(gribbit) & kermit.setColour(gribbit.getPosition()) do the exact same things.
a message answer -- the colour of the receiver. Also note that setColour() doesn’t return a message answer. It certainly does something (changes the colour of the receiver) but it doesn’t return a value.
receiver. That’s their purpose. We use them to ‘get’ a value. Examples: getColour(), getPosition(), getHeight() Setter message Are used to change the state of the receiver. We use them to ‘set’ one or more attribute values of the receiver. We set these values to the argument(s) of the message, so setter messages always involve arguments. Examples: setColour(OUColour.GREEN), setPosition(2), setHeight(3)
to include associated getter and setter message for each of its attributes. So if we have a Book object with the attributes: title, and author, then we would programme the object to understand the messages: • getTitle() - returns the value of title • setTitle() - sets the value of title • getAuthor() - returns the value of author • setAuthor() - sets the value of author
set the colour of a Frog object using an argument like OUColour.GREEN (for example) rather than simply the argument green. This will be explained and made clearer in later units. For now, just consider the two things one and the same: so OUColour.GREEN just means the colour green to us right now.
• A class is like a blueprint for object creation. It defines a group of objects. • Instances of the same class have the same protocol, behaviour, and the same attributes as each other. • Each instance of a class is initialised in the same way -- they are created with the same state. • Each instance of a class has their own data – their own copy of their attributes that belong only to them and the value of which can change (for example by sending the object a setter message).