Home Segments Index Top Previous Next

80: Mainline

In Chapter 2, you learned you can multiply 194 by 9, hence computing the number of calories in 194 grams of fat, as follows:

194 * 9 

Of course, if you propose to compute calorie content many times, you should arrange for the appropriate work done by a new method, as in the following expression, in which a fatToCalories message is sent to an instance of the Integer class:

194 fatToCalories 

To respond to the fatToCalories message, the receiver, 194, must find the method identified by the fatToCalories selector and follow the instructions found in that method.

Accordingly, you must learn how to define a fatToCalories method appropriate for fatToCalories messages sent to instances of the Integer class.