RU beehive logo ITEC Department logo
ITEC 120
2007spring
ibarland,
jpittges

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

design-recipe
the design recipe

The design recipe1 is a series of steps to guide you through writing a program. Not only does it get you past any initial blank-screen anxiety, but its structure helps guide your thinking in a way which reduces the number of bugs you'll encounter.

This recipe will get further fleshed out as the semester progresses; ignore (for now) the greyed-out text.

  1. Data analysis — What are the pieces of information at hand, for this problem, and which data types should be used to represent them in the program? (E.g., int, String, boolean, ...?)
  2. Examples of the data. Make a bunch of example instances.
    (If using BlueJ with unit test tools enabled, you can create these these instances by right-clicking on the class; then you can right-click on the test-class and select “Bench to test fixture”.
  3. Signature — for each method (function), specify its name, what input parameters it needs (name and type), and what type of information it will return. (See our mantra for signatures)
  4. Comments (written in javadoc). Describe what each parameter means (for example “the price of the item, in dollars”, or “the number of students officially enrolled in the course”) as well as the meaning of the return value.
  5. Complete the stub function, and compile. Note that you still haven't yet written any code which computes a solution.
  6. Test cases: Write 2-3 test cases (or more, as appropriate).
  7. The body of the function. This is the only non-automatic part of the process. Reflect on the test cases you worked through by hand: how did you get from the input to the output? What is the general case?

    Things to help you on your way:

    1. Remind yourself of your parameters and fields -- these are the only pieces of info you have, to calculate your answer!
    2. What are the types of each of these data? What pertinent methods can you call, on objects of that type?

  8. Test — run the test cases you already wrote down from step 2. Does your program give the results you expect?
  9. Refactor — review and (as necessary) rewrite your code. Does it obey the The Laws of Programming?

1This design recipe is adapted from How to Design Programs, by Felleisen, Findler, Flatt, and Krishnamurthi.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Aug.27 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme