Software Design (CSC-223 97F)
Notes on Assignment 5: I/O Interfaces
Your interfaces were significantly less good than I would have hoped.
Here are some of the problems that you may want to correct before
beginning the next assignment.
- I was glad to see many of you talking about whitespace its
effect on input and output. If you weren't one of the groups
that thought about whitespace, you should be.
- I was glad to see many of you throwing exceptions. If you
weren't one of the groups that threw exceptions, you should be.
If you did throw exceptions, make sure you carefully specified where
the "file pointer" would be after the exception was thrown.
- Some of you are attempting to modify parameters which have primitive
double. Unfortunately, Java passes primitive types
by value rather than by reference. This means
that changes to parameters within methods are not reflected
outside the method.
- A similar problem may occur if you try to
pass and change objects of the simpler classes, like
Boolean, as Java disallows
modifications to the values of such objects (note that there
String.setValue() method, or anything similar).
- Hence, you are probably better off returning values from your
readXXX() methods, rather than passing
a buffer into those methods.
- Some of you have file input and output methods, but don't have
If no such methods are available, how does a programmer differentiate
between appending to a file and rewriting the file? If no such
methods are available, how does a programmer differentiate between
reading the next element of a file, and rereading the first element
of a file?
- More importantly, why make the file (or stream or ...) a parameter to
all the methods, when you can just make it a parameter to the
- Many of you had no constructors, which I found surprising. Make sure
to add some (probably using my recommendation above).
- I'd really like to see better
Try to have at least a sentence on each method.
- A few of you forgot about padding, which is used to ensure that
an output value takes at least some number of spaces.
- You should make it clear what happens when the value
needs more than the given number of spaces.
- You should make it clear whether the padding happens on
the left or right.
- You should make it clear what character is used for padding.
Often, spaces are used for left padding and 0's are used for
right padding (at least when we're dealing with numbers).
- If you're going to use constants in your program, you need to declare
them (and that's part of the initial design).
- It would be much nicer if you could use the same routines (or at
least routine names) for both file I/O and standard I/O.
- Some of you chose to have a
File parameter to all of
your methods. In order to use standard input or standard output,
the programmer had to rely on
constants. Rather than having such
why not provide a separate version of your functions with one less parameter?
- When we were talking about buffering, I mentioned that it is often
necessary to "unread" characters. You should provide some form of
unreading, but you may certainly limit how much unreading is done
(one character is certainly sufficient).