The ORDER method
The alternative to MAP is an ORDER member function, which compares two methods: SELF, and another object of the same type that you supply as an argument. You want to program the function to return an integer that is positive, zero, or negative, indicating the ordering relationship of the second object to SELF. Table 21-2 illustrates the behavior you need to incorporate.
Table 21-2. Desired behavior of ORDER member functions | |
For these desired semantics... | Your ORDER member function must return |
SELF < argumentObject | Any negative number (typically -1) |
SELF = argumentObject | |
SELF > argumentObject | Any positive number (typically +1) |
Undefined comparison | NULL |
Let's take a look at a nontrivial example of an ORDER method.
Here are the important things to note:
Lines 21-24
This means that "books sort higher than serials."
Lines 26-46
This is an equality test that uses a very cool feature. Because Oracle doesn't know how to compare collections, this code uses Oracle's ability to select from a collection as if it were a table. By checking to make sure that the relational intersection of these two collections has the expected number of elements, I can determine whether every element in the first collection has an equal counterpart in the second (which is my definition of "equality").
Overall, however, my ORDER method is still inadequate because it fails to treat the subtype-specific attributes, but anything longer would just be too unwieldy for this book.