Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 1. Some Basic Ideas > 1.8 TOP-DOWN DESIGN WITH STEPWISE REFINEMENT

1.8 TOP-DOWN DESIGN WITH STEPWISE REFINEMENT

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

  1. Assemble materials

  2. Paint the wall

  3. Clear up afterwards

Refinements

  1. Assemble materials

1.1 Decide on paint colour (you may need to discuss this first!)

1.2 Visit store and buy the paint

1.3 If there is no clean paintbrush or roller visit hardware DIY shop and purchase one


  1. Paint the wall

2.1 open the paint can (do not forget this step!)

2.2 stir the contents

2.3 apply the paint


2.3 Apply the paint (a repeated action, describe it as loop).

2.3.1 loop while job is not finished

2.3.2 dip brush (roller) in paint

2.3.3 rub it over the wall

2.3.4 endloop


  1. Clear up afterwards (the effort needed depends upon your previous care and skill)

3.1 clean paint from window frames

3.2 clean paint from window glass

3.3 clean paint from carpet

3.4 clean paint from dog/cat/parrot/other

3.5 clean paintbrush/roller (I usually forget)


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

  1. get the sum in GBP to convert

  2. perform the conversion to USD

  3. write out the result

Refinements

  1. get the sum

1.1 prompt the user to enter sum in pounds


  1. perform conversion

2.1 establish conversion rate factor

2.2 multiply sum in GBP by conversion factor to give dollars


  1. 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.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint