Lecture Notes for Advanced Programming II

13 February 2001 - Classes and Abstract Data Types


  1. an abstract data type

    1. a class without inheritance

    2. what's left - enforced information hiding; enforced interface definitions; type definitions; first-class citizenship

    3. but isn't inheritance important - well, no; understanding inheritance is hard; understanding classes using inheritance is hard; there's always the contains-a relation

  2. interface and implementation

    1. interface - the functions (and sometimes data) made available by the adt

    2. implementation - the function code, types, and data used in the adt

    3. this is just our library discussion continued - a class is a library

  3. adt state

    1. state is what distinguishes two instances of an adt

      1. stack<int> is1, is2;
        is1.push(0);
        

      2. is is1 different from is2 - how

      3. logical state - what the adt user thinks about; stack of integers

      4. physical state - what the adt implementer thinks about; array of integers, an index value

    2. adt correctness involves state - logical state, physical state and the relation between logical and physical state

      1. state is consistent if all values hang together - logical, physical, and their relation

      2. class invariants - the correct relations among the values in physical state; important for understanding classes

    3. adt consistency also involves state

      1. similar state behaves the same - consistency

      2. no surprises

  4. class (library, adt) rules

    1. redundancy - can be good (reliability) or bad (repeated computation); unused redundancy is bad

    2. don't copy code; turn it into a procedure - constructors

    3. dynamic storage - always a problem; the assignment operator


This page last modified on 13 February 2001.