Java Reference
In-Depth Information
1. Write noun phrases to describe the objects to be manipulated.
For example, if a program is going to manipulate student records, here are
some of the objects that we might consider:
student name,
student address,
student major (e.g. English or Computer Science),
student's advisor,
grades in courses,
complete student record (it contains just about all the other objects).
As another example, a program that manipulates graphical shapes and places
them in a window on your monitor will deal with things like the position of a
shape on the monitor, the kind of shape, the color of a shape, and the angle at
which the shape is drawn.
Not all the objects listed will require new class definitions. For example, a
student's name may be implemented as a String , which is already a class. Other
objects might appear at first to be useful in the real world but may not be neces-
sary for the program that is being written.
With the list of possible objects, we can:
2. Decide on classes and write their specifications.
The instances of these classes will be the objects.
Recall that the specification of a class describes the behavior of instances of
the class, meaning that it specifies all the non-private methods of the class. It will
also specify the non-private variables. This is done by picturing in your mind the
behavior of the object —in terms of both the real world and how you expect it to
perform in the program. In this sense, the verbs that come to mind end up being
the method names. For example, we might have to change a student's address
(method changeAddress ), or insert a grade ( insertGrade ), or send a message
to the student's advisor ( mailAdvisor ).
numberOfAccounts() {… }
BankAccount(String, double ){…}
Figure 3.8: BankAccount 's file drawer, with one instance
Search WWH ::

Custom Search