|
|
c m s c 214
f a l l 2 0 0 1 |
When you're implementing a class, it's very easy to get caught up with the implementation. For example, you might be writing a class that uses a dynamic array or a linked list. However, try to remember that often, you are writing this class (in principle) for other programmers to use.
Very often, you are trying to create some mathematical entity. These entities are considered "abstract", because they aren't implemented. For example, when you think of a set, you think of something that looks like {1, 3, 5, 10}.
You may know something about sets already. For example, no elements are repeated, and sets are unordered.
When you implement a set, however, you have to think about whether it should be implemented using a dynamic or static array, or whether you should use some sort of linked list. It's easy to get so concerned about linked lists and arrays that you forget that the person using your class just doesn't care. All they want to do is to use a Set.
Thus, you have to provide methods that will get them to think of your class as a set. This is very similar to designing, say, a television. As a designer, you always keep in mind that the user only worries about getting a good quality picture, and wants some basic operations. They don't ever want to think about how the TV is constructed. They don't want to know about the electronics or physics that make televisions possible.
As you implement a doubly linked list, think about what you are presenting to the user. You want the user (who is really a programmer using your class) to think of this as a sorted list.
A sorted list may seem like an obvious concept (especially if it's a list of integers), but there are some subtleties.