22 A World of Interacting
The two examples in this chapter illustrate the "world of interacting objects" that is
typical of a program built using classes. They give you a practical model for an
alternative to the "top-down" design approach used extensively in Part III. The
examples also illustrate slightly simplified, informal versions of some of the schemes
that are commonly used to document more elaborate object based programs.
The first example, "RefCards", is a little bit like the example in Section 17.3. In that
example, a program manipulated "customer records" that contained data such as
customer name, and amount ordered. Actually, that program manipulated a single
structure in memory; the rest of the records were in a file. When a record was needed,
it got loaded into memory. Now we can use things like an insane of a standard "list"
class to hold a collection of records in memory, transferring these records to and from
disk only when the program finishes and is restarted. The data records this time are
"reference cards" – the sort of thing used to keep references to papers when you are
doing scientific research. These records contain things like "authors' names", "paper
title", "journal", and "page numbers". Although the RefCards program has some
similarities to the earlier example, the use of classes in its design results in an
implementation that is beginning to show a quite distinct structure.
The second example is an object-based reworking and elaboration of the
"information retrieval" example from Section 18.3. That version of the program
allowed the user to build up files containing newspaper articles, with an index based on
a predefined set of keywords defined by an initialized data array. It used two programs.
One added data to the file; the other performed single searches. Now we need
something more general.
The program is to allow the user to define the "vocabulary" of keywords (as in the
earlier example, it is actually a vocabulary of concepts as several different words can