(^24) | Introduction to Object-Oriented Programming
to discuss them with the person who assigned you the task.
Here are some of the questions you might ask in the context of programming:
What do I have to work with—that is, what objects does the problem require?
What do the objects look like?
What tasks do the objects perform on their data?
How much input is there?
How do I know when I have input the last value?
What should my output look like?
How do the objects work together to solve the problem?
What special error conditions might come up?
Look for Things That Are Familiar
Never reinvent the wheel. If a solution already exists, use it. If you’ve solved the same or a
similar problem before, just repeat your solution. In fact, people are good at recognizing sim-
ilar situations. We don’t have to learn how to go to the store to buy milk, then to buy eggs,
and then to buy candy. We know that “going to the store” is always the same; only what we
buy differs on each trip.
In programming, certain problems occur again and again in different guises. A good pro-
grammer immediately recognizes a subtask that he or she has solved before and plugs in the
solution. For example, finding the daily high and low temperatures is really the same prob-
lem as finding the highest and lowest grades on a test. You want the largest and smallest val-
ues in a set of numbers (see Figure 1.13).
Use the same
method to
find these
values in
both cases.
Highest = 9 5
Lowest = 1 8
Highest = 9 8
Lowest = 1 2
List of Temperatures List of Test Scores
42
18
27
95
55
72
33
78
86
61
58
91
27
14
55
98
72
66
45
12
39
70
68
Figure 1.13 Look for Things that Are Familiar