Algorithms and OOD (CSC 207 2013F) : EBoards

# CSC207.01 2013F, Class 25: The Collections API

Overview

• Preliminaries.
• Making our list interface generic.
• Beyond our own design: The collections API.

• No readings for Monday. Work on the exam!
• Upcoming extra credit opportunities
• Codebreaker Friday night at 7pm in Harris.
• Codebreaker discussion after the movie.
• Drake Library book sale this weekend
• I already have corrections to the exam, but have not made them. Keep sending them in.
• I should have the repo up soon.
• Cool booksale this weekend.
• 10/10 is this weekend. Please behave responsibly. Please take care of yourself and each other.
• And help the people on Cowles and Younker 1st recover
• EC for going to Wartburg this weekend and cheering on Xcountry

Exam Questions

• What's the name of the class that sorts for DNF (DNF.dnf).
• Can DNF.dnf throw exceptions? No. If you fail to meet preconditions, it can do whatever it wants.
• Do we have to deal with incorrect inputs for DNF.dnf? No. You just want to make sure that it works correctly with correct inputs.
• For problems 4 and 5, do we just have to implement the STUBs, or add procedures.
• Just finish the STUBs.
• Can you explain a bit more about what you want for loop invariants?
• A loop invariant is a condition/assesrtion that, if holds at beginning of the loop, also holds at the end.
• Specific enough that it helps you understand the problem.
• General enough that you can guarantee that it holds.
• Note: The invariant can be temporarily invalidated in the middle
• For this problem, the only things we know about are:
• The total number of beans in the jar
• The number of dark beans
• The number of light beans

## Making our list interface generic

• How do we generalize the following so that it works for Integers or UshahidiIncidents, or BigDecimals, or whatever?
• Strategy one (early Java): Use Objects
• Yay polymorphism! We can put Strings or UshahidiIncidents or ... into the list.
• And our lists can be heterogeneous - We can have an Integer and a String
• But heterogeneity can be problematic. How do you map or sort or .... a heterogeneous list?
• Java philosophy: Catch possible type errors at compile time rather than run time Scheme: (define whatever (x) (* x x)) ... (define morestuff (fun y) (whatever (fun y))) Java wants to know before you run the program whether you'll have type errors.
• Java redesign: Allow "generic" structures that still do some kind of type checking, so that we can enforce type safety.
• Soln': Parameterize a class definition ("Generics") class ListOf we can plug in type variables, much like we plug in variables elsewhere