Dale - Computer Science Illuminated 311

Dale - Computer Science Illuminated 311 - in the Delete...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
284 Chapter 9 Abstract Data Types and Algorithms Constraints on the Print operation break the list into subcategories. Should the items be printed in the order in which they are inserted? Should the items be printed in order by some information in the items themselves? Answering yes to the first question leads to an unsorted list. Answering yes to the second question leads to a sorted list. How can we consider Print item concrete when we know nothing about the items on the list? That’s just it. We consider this list to be generic so each item on the list must know how to print itself. Print item just tells the item to print itself. Before we continue with the decomposition of the responsibility algo- rithms in the two subcategories, let’s spend a moment on the implication of the Find the item
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: in the Delete operation. Finding an item means that the class to which an item belongs has a way of recognizing a match. It is not the responsibility of the list to know what a match is; it is the responsibility of ItemClass . We need to make this assumption explicit somewhere. Let’s add an assumption to the CRC card that ItemClass must provide a compareTo method and indicate what the results must be. Java has a 10–2678.0 method defined on items of class )C7>!O and other classes in the Java Library. Let’s use that definition. We also need compareTo in the Find where item belongs in the sorted list. Know Length return length Print While ( more items ) Get next item Print item Delete(item) Find the item Remove the item Decrement length...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online