User's Guide
The calculator works as it is. Still, as a design consideration,
consider that at some time in the future you might want to change the numeric
display on the calculator. You might want to either change the
STCalculator class or subclass it to use something different than a
CwText as the display.
To make this possibility easier, let's change the name of the instance
variable textWidget to display. The name
textWidget reveals too much of the current implementation of the
display, which might change in the future.
How should you do this? You cannot just go and change the name of the
variable. Some methods refer to this variable, and when you save the
definition of a class, all of its methods get recompiled. Those methods
which reference textWidget do not compile. Do the following
to change the variable:
- In the Applications Browser, select the STCalculatorApp
application; then select the STCalculator class.
- Add display as an instance variable. Do not remove
textWidget yet. Save the text.
- After the class has recompiled, from the Classes menu, select
Browse References > To An Instance
Variable.
- Select textWidget, then OK. A References
browser opens. The top pane contains the methods that refer to
textWidget.
- Select STCalculator>>addButtonsTo:. The source
code for the method is displayed in the lower pane, with the first reference
to textWidget highlighted.
- Replace the highlighted textWidget with
display. Save the method from this pane.
- Select the next method, addDisplayTo:. Note that
the title of the window now reads (1 of 2). This indicates
that addDisplayTo: refers to textWidget two
times.
- Replace the first occurrence of textWidget with
display.
- From the Methods menu, select Next Range. The
browser moves to the second reference.
- Change the remaining references to display, making sure to save
each method as you go.
- Close the References browser.
- In the Applications Browser, remove textWidget from the
definition of STCalculator. Save the class
definition.
You have now changed the name of the instance variable.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]