< previous page page_1060 next page >

Page 1060
FIGURE 18-6 (continued)
    void Delete ( /* in */ ComponentType item );
        // Precondition:
        //     item is somewhere in list
        //  && List components are in ascending order
        // Postcondition:
        //     item is no longer in list
        //  && List components are in ascending order

    OrdList();
        // Constructor
        // Postcondition:
        //     Empty list is created

    OrdList( const OrdList& otherList );
        // Copy-constructor
        // Postcondition:
        //     List is created as a duplicate of otherList

    ~OrdList();
        // Destructor
        // Postcondition:
        //     List is destroyed
private:
    NodeType* head;
};
In Chapter 15, we classified ADT operations as constructors, transformers, observers, and iterators. IsEmpty and Print are observers. InsertTop, Insert, DeleteTop, and Delete are transformers. The class constructor and copy-constructor are ADT constructor operations.
In the class declaration, notice that the preconditions and postconditions of the member functions mention nothing about linked lists. The abstraction is a list, not a linked list. The user of the class is interested only in manipulating ordered lists of items and does not care how we implement a list. If we want to change to a different implementation-an array, for example-neither the public interface nor the client code would need to be changed.
The private data of the OrdList class consists of a single item: a pointer variable head. This variable is the external pointer to a dynamic linked list. As with any C++ class, different class objects have their own copies of the private data. For example, if the client code declares and manipulates two class objects like this:
OrdList list1;
OrdList list2;

 
< previous page page_1060 next page >