A task must supply the proper arguments with the message in order for the method to execute. When an object receives a message with its accompanying arguments, it takes over operation, executing the method and dealing with the results of execution.
Object variables are internal to the object, and should not be touched directly by a task working with an object.
Each instance of a class has its own data space and variables that record the state of the instance. The instance also contains pointers to the methods defined by the class. When an object receives a message, the object calls one of the class methods which executes using the calling object's variables.
For example, consider a class that defines an employee object. The object has several variables which record the employee's name, date of hire, date of termination, and salary or hourly rate. The object has one method which accepts a Pay Rate message. When the method executes, it prints the employee's rate of pay or the termination date if the employee has left the company.
If a program creates two employee objects that have the following variable values:
Table 1: Employee object variable values. -------------------------------------------- employee1 |employee2 -------------------------------------------- John Smith |Jane Doe -------------------------------------------- 10/21/90 |2/23/92 -------------------------------------------- $20/hr |$40,000/yr -------------------------------------------- 3/3/94 |null --------------------------------------------
If a Pay Rate message is sent to each object, the employee1 object prints the date that John Smith left the company. The employee2 object prints the annual salary for Jane Doe. Identical messages to objects of the same class can produce different results when the state of the object variables is different.