Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
There are a number of design techniques, and a simple but useful one is 'top-down stepwise-refined design'. It is less helpful for large or 'object-oriented' (O-O) programs but can still be used for individual 'modules' or functions within those programs.
In this process, state in general terms—the top level—what the program is to do, identifying a number of steps to be performed in sequence. Do not aim for too much detail initially, but do get the sequence right! Now move on to each step and gradually clarify it, breaking it into sub-steps if necessary. Carry on using logical, clear terms until each step is detailed enough to write as a statement in the chosen language. It may be helpful at first to number each step and its sub-steps, as in the following example. From this design, identify the data to be used.
Top-down design is a general problem-solving activity, so let us provide an illustration of its use to describe how to set about painting a living-room wall to someone who has never done it before. It is not intended to become a computer program, but if I get around to creating a household chores robot (one day, I hope) this might form part of its software.
Top level
Assemble materials
Paint the wall
Clear up afterwards
Refinements
Assemble materials
|
Paint the wall
|
2.3 Apply the paint (a repeated action, describe it as loop).
|
|
Let us take a simple but more computer-oriented example. Convert a sum, value supplied by the user, in one currency such as British pound sterling (GBP) into another, say, United States dollar (USD).
Top level
get the sum in GBP to convert
perform the conversion to USD
write out the result
Refinements
get the sum
|
perform conversion
|
write out sum in USD
This simple example shows the steps to be carried out and the order in which this must be done. Code it once you have read Chapter 2, which introduces the syntax of Java if you are unfamiliar with the language.
We shall use pseudocode extensively throughout the book to develop example programs.