Home Segments Index Top Previous Next

272: Mainline

Then, if you decide to switch to gram-based instance variables, you need to make no change to tCalories; instead, you redefine the getters such that they access the new gram-based instance variables. From the behavior perspective, the altered getters provide the same answers as the original getters:

Food class definition 
Object subclass: #Food 
  instanceVariableNames: 'pGrams cGrams fGrams' 
  classVariableNames: '' 
  poolDictionaries: '' 
Food method definition • instance 
fCalories ^ fGrams * 9 
Food method definition • instance 
cCalories ^ cGrams * 4 
Food method definition • instance 
pCalories ^ pGrams * 4