< previous page page_160 next page >

Page 160
One of the advantages of implementing modules as functions is that they can be called from different places in a program. For example, if a problem requires that the volume of a cylinder be computed in several places, we could write a single function to perform the calculation and simply call it in each place. This gives us a semihierarchical implementation. The implementation does not preserve a pure hierarchy because abstract steps at various levels of the solution tree share one implementation of a module (see Figure 4-6). A shared module actually falls outside the hierarchy because it doesn't really belong at any one level.
Another advantage of implementing modules as functions is that you can pick them up and use them in other programs. Over time, you will build a library of your own functions to complement those that are supplied by the C++ standard library.
We postpone a detailed discussion of hierarchical implementations until Chapter 7. For now, our programs remain short enough for flat implementations to suffice. Chapters 5 and 6 examine topics such as flow of control, preconditions and postconditions, interface design, side effects, and others you'll need to develop hierarchical implementations.
From now on, we use the following outline for the top-down designs in our case studies:
Problem statement
Input description
Output description
Discussion
Assumptions (if any)
Main module
Remaining modules by levels
Module structure chart
0160-01.gif
Cartoon by M. LAD. TOPOLSKY

 
< previous page page_160 next page >