University of Virginia, Department of Computer Science
CS201J: Engineering Software, Fall 2002

Notes: Tuesday 10 September 2002
Assignments Due

Notes and Questions

What are the advantages and disadvantages of using abstract data types?






Specifying Abstract Data Types

StringSet Specification
public class StringSet
    // OVERVIEW: StringSets are unbounded, mutable sets of
    //     Strings.  A typical StringSet is { x1, ..., xn }
    public StringSet () 
        // EFFECTS: Initializes this to be empty: { }
    public void insert (String s) 
        // MODIFIES: this
        // EFFECTS: Adds x to the elements of this: 
        //       this_post = this_pre U { s }
    public boolean isIn (String s) {
        // EFFECTS: Returns true iff s is an element of this.
    public int size () 
        // EFFECTS: Returns the number of elements in this.


Representation Invariant

The Representation Invariant expresses properties all legitimate objects of the ADT must satisfy. It is a function from concrete representation to boolean:

I: C → boolean

To check correctness we assume all objects passed in to a procedure satisfy the invariant and prove all objects satisfy the invariant before leaving the implementation code.

public class StringSet {
   // OVERVIEW: StringSets are unbounded, mutable sets of Strings.
   //    A typical StringSet is {x1, ..., xn}

   // Representation:
   private Vector rep;

   // RepInvariant (c) = c contains no duplicates && c != null
Abstraction Function

The Abstraction Function maps a concrete state to an abstract state:

AF: CA
It is a function from concrete representation to the abstract notation introduced in overview specification.
   // AF (c) = { AFString (c.els[i]) | 0 <= i < c.els.size () }
It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.

Alan Perlis


CS201J University of Virginia
Department of Computer Science
CS 201J: Engineering Software
Sponsored by the
National Science Foundation
cs201j-staff@cs.virginia.edu