Java Reference
In-Depth Information
As a computer scientist, you should be familiar with both types of problem solv-
ing. This topic begins with procedural decomposition and devotes many chapters to
mastering various aspects of the procedural approach. Only after you have thorougly
practiced procedural programming will we turn our attention back to object decom-
position and object-oriented programming.
As an example of procedural decomposition, consider the problem of baking a
cake. You can divide this problem into the following subproblems:
Make the batter.
Bake the cake.
Make the frosting.
Frost the cake.
Each of these four tasks has details associated with it. To make the batter, for
example, you follow these steps:
Mix the dry ingredients.
Cream the butter and sugar.
Beat in the eggs.
Stir in the dry ingredients.
Thus, you divide the overall task into subtasks, which you further divide into even
smaller subtasks. Eventually, you reach descriptions that are so simple they require
no further explanation (i.e., primitives).
A partial diagram of this decomposition is shown in Figure 1.2. “Make cake” is
the highest-level operation. It is defined in terms of four lower-level operations called
“Make batter,” “Bake,” “Make frosting,” and “Frost cake.” The “Make batter” opera-
tion is defined in terms of even lower-level operations, and the same could be done
for the other three operations. This diagram is called a structure diagram and is
intended to show how a problem is broken down into subproblems. In this diagram,
you can also tell in what order operations are performed by reading from left to right.
That is not true of most structure diagrams. To determine the actual order in which
subprograms are performed, you usually have to refer to the program itself.
Make cake
Make batter
Bake
Make frosting
Frost cake
Mix dry
ingredients
Cream butter
sugar
Beat in
eggs
Stir in dry
ingredients
Figure 1.2
Decomposition of “Make cake” task
 
Search WWH ::




Custom Search