RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

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.

    For each entire project/homework

  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. If you are writing a new class, make a bunch of example instances.
    (Once we've introduced constructors, this entails writing the constructor for the class, so that you can call it.)
    (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. For each individual function/method in the homework…

  4. 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)
  5. Complete the stub function, and compile.
    Note that you still haven't yet written any code which computes a solution.
  6. 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.
    (You can do this either before or after your test cases.)
  7. Test cases: Write 2-3 test cases (or more, as appropriate).
  8. 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?

  9. Test — run the test cases you already wrote down from step 2. Does your program give the results you expect?
  10. 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


©2008, Ian Barland, Radford University
Last modified 2008.Jan.24 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme