ADT ITEC 320 Lecture 22
Review • Generic lists • Ada compilation workout • Recursive algorithms • What would a recursive copy look like? • Project 4 is up (Dr. Okie’s site) • Due next Tuesday at 10PM
Outline • ADTs • What are they ? • Why should we study them? • What are they good for?
Definition • A type in which • What the operations of the type are is public • How it is implemented is private • Abstract because irrelevant details are ignored • i.e. how it is implemented is ignored • Benefits / dangers of how something is implemented
Place • Top down software design • Decompose into smaller problems • Bottom up software design • Have tool, use tool • Design new tool if not in toolbelt
Examples package BigNumPkg is type BigNum is private; Zero : constant BigNum; One : constant BigNum; BigNumOverFlow: exception; function toString(X: BigNum) return String; function "<" (X, Y : BigNum) return Boolean; function ">" (X, Y : BigNum) return Boolean; function "<=" (X, Y : BigNum) return Boolean; function ">=" (X, Y : BigNum) return Boolean; function "+" (X, Y : BigNum) return BigNum; function "*" (X, Y : BigNum) return BigNum; procedure Get (Item : out BigNum); procedure Put (Item : BigNum; Width : Natural := 1); private Size : constant Positive := 50; type BigNum is array(0..Size-1) of Integer; end BigNumPkg;
Design a • Stack • Queue • How would you take a doubly linked list and use it to make a stack / queue?
Support • Ada • Package • Java / C++ • Classes (Java packages != Ada packages) • C • What do you think? • Others • modules
Defining • Values it holds • Set of operations it performs • Declaration • Allocation • Modification • Querying, Modifying, Combination, conversion, input/output • Iteration
Iterators • What does the term mean to you? • Traversal versus access + printing Tree t = new Tree(); // Add some elements here Iterator i = t.getIterator(); while i.hasNext() S.o.p(i.next());
Why? • Simplicity • High level operational thinking • Abstractions on top of abstractions • Reliability • Flexibility • Independence
Design principle • Parnas Principle • Maximize cohesion • Minimize Coupling • Why?
Question • What should make up a standard library of ADT’s?
Summary • ADTs