CSE 331�Software Design & Implementation
Spring 2026
Section 4 – Mutable Specs & Data Abstraction
Administrivia
Specifications for ADTs – Review
public class List {
final int hd;
final List tl;
}
State Representations
Internally Documenting ADTs – Review
Abstract Function (AF) – defines what abstract state the field values represent
Representation Invariants (RI) – facts about the field values that must always be true
Documenting ADTs – Example
// A list of integers that can retrieve the last element in O(1)
interface FastList {
/**
* Returns the object as a regular list
* @returns obj
*/
List toList();
}
class FastLastList implements FastList {
// RI: this.last = last(this.list);
// AF: obj = this.list;
// @returns last(obj)
int getLast() {
return this.last;
};
}
Hide the representation details (i.e. real fields) from the client
Talk about functions in terms of the abstract state (obj)
Externally Documenting ADTs - Review
* @modifies states what could be mutated by function (obj)
* @effects Detailed description of guaranteed changes
/**
* High level description of what function does
* @param a What "a" represents + any conditions
* @requires Rules about multiple params and Abstract State (obj)
* @returns Detailed description of return value
* @throws Condition when errors will be thrown
*/
Specification Strength Mutation - Review