![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
A fourth virtue of procedure abstraction is that you can augment repetitive
computations easily. For example, you saw the fatToCalories
method
defined this way in Segment 89:
Integer method definition instance fatToCalories ^ self * 9
You can add a line that displays the calories in fat every time that such calories are computed:
Integer method definition instance fatToCalories Transcript show: 'The number of fat calories computed is '; show: (self * 9) printString; cr. ^ self * 9 Workspace 194 fatToCalories Transcript The number of fat calories computed is 1746
Thus, to add the display capability, you do not need to find all the places
where calories are computed from fat grams, because you need to change only
the definition of the fatToCalories
method.