SUNY Geneseo Department of Computer Science


Creating Subclasses of List

{Date}

CSci 141, Spring 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Dept. talk on spoken language interfaces

Making appointments

Exam 2 will be Thursday (April 1)

Practice Exam on Web

Questions?

Final comprehensive but biased to material since last hour exam, designed for 2 hours, same rules as hour exams

For hour exam, know roughly what messages you can send to lists

List of integers, all have to be wrapped

    someList.addItem( new Integer( i ) );
    ....
    ...x + ((Integer)someList.getFirst()).intValue()...
    int y = ((Integer)someList.getFirst()).intValue();
    ... x + y ... 

Proof for red tiles

List Subclasses

Section 11.5.1

The makeNewList factory method

[Extending a SquareBoxyList with Internal SquareBoxyLists]

    addItem ( n )
        temp = this.makeNewList()
            // vs temp = new List()
        temp.head = this.head;
        temp.tail = this.tail
        this.head = n
        this.tail = temp
        public List makeNewList() {
            return new ...this subclass...
        }
        // In class SquareBoxyList:
        public List makeNewList() {
            return new SquareBoxylist();
        }
        public SquareBoxyList() {
            super();
        }

Why casts?

Next

Stacks - a list-like class

Read


Next Lecture