with attribute values. These attribute values are collectively called its state and we can also think of state as the object’s data. Initialisation is the setting of an object’s state upon its creation. It is called this because it gives the attributes their initial value.
class Frog). A Frog object has the attributes colour and position. All instances of Frog are created with these attributes set to the same initial values. In the case of Frog objects, these are: • colour is initialised to green • position is initialised to 1
within the class (and this is explained in later units). Right now we just need to recognise that no matter how many instances of the Frog class we create, they will all begin with the same initial state. It is only through the sending of messages that instances of the Frog class can alter in state.
objects) in addition to instances of Frog. Toad objects also have the attributes colour and position, but are instead initialised to have a position of 11 and a colour of brown. So we can see that Frog objects and Toad objects are both instances of different classes and these classes initialise them differently.
attributes, but are initialised differently. However, it wouldn’t be hard to imagine two instances of different classes that have completely different attributes to each other. For example -- a Pen object with the attribute ink, and a guitar object with the attributes wood and strings – both share no common attributes (as we would expect as they represent completely different objects.)
addition to being initialised differently, instances of Frog and Toad also have different protocols. We can see that Frogs understand the message jump(), but Toads don’t. So we say that jump() is not in the protocol of Toad.
Frog and Toad objects do understand but which cause different behaviour when they are received. For example, the message home() returns a Frog object to position 1, whereas the message home() returns a Toad object to position 11. Toad objects also move an additional step in response to left() and right() than Frog objects do.
is useful because we only need to write the code to define the object once -- in the class. Then we can make virtually as many copies of the object as we like, each of which holds their own unique data (in the form of attribute values) and can communicate with other objects.
of the programmer, and the chance of introducing errors to the code. Also, if we need to change any attribute or behaviour of a class of objects then we only need to make this change in once place: the class.