(^526) | Array-Based Lists
CRC Card
Although we have designed our CRC card for a to-do list, the responsibilities outlined remain
valid for any kind of list. For example, if we are creating a list of people to invite to a wedding,
all of these operations are valid. We add names to the list, check whether a name is already
on the list, count the names on the list, check whether the list is full (that is, the length is equal
to the number of invitations bought), delete names, and review the names one at a time.
To make the rest of the discussion more concrete, let’s first assume that the items on the
list are strings. Later, we will see how the items can be made even more general.
Refining the Responsibilities
Let’s go back through the responsibilities, refining them, and converting them into method
headings. Because we are designing a general-purpose class, we do not have any specific sce-
narios that we can use. Instead, we will consider a variety of simplified scenarios that exemplify
how we believe the class may be employed. Because the class is intended for widespread use,
we should pay special attention to the documentation right from the design stage.
The observers, testing for full and empty, returning the number of items, and checking
whether an item is in the list, need no further discussion. Here are their method headings:
Class Name: List Superclass: Object Subclasses:
Responsibilities Collaborations
Create itself (maxItems) None
Is list full? None
return boolean
Is list empty? None
return boolean
Know length
Delete from list (item)
None
return int
None
Set up for iteration None
Know next item None
return boolean
Insert into list (item) None
Is an item in the list? None