Chapter 18: Objects and Classes
Code examples of the chapter are grouped into nine directories. Files in different directories with the same names are identical:
- Directory intpair_fraction_rational contains definitions of three classes (Pair, Fraction, Rational), and a test of them. Pair is a pair of int values.
- Directory pair_fraction_rational contains definitions of three classes (Pair[K,V], Fraction, Rational), and a test of them. Pair is generic, and Fraction instantiates it as Pair[int,int].
- Directory intarraylist contains a definition of the class ArrayList for items of type int, and a test of it.
- Directory arraylist contains a definition of the generic class ArrayList[E], and a test of it.
- Directory hashset contains a definition of the generic class HashSet[E], and a test of it.
- Directory enumerate_rationals_with_array_list uses ArrayList[Rational] to enumerate Rationals, and a timing thereof.
- Directory enumerate_rationals_with_hash_set uses HashSet[Rational] to enumerate Rationals, and a timing thereof.
- Directory enumerate_rationals_with_gcd eschews use of either ArrayList or HashSet to maintain the collection of already-enumerated Rationals. Rather, it just emits reduced fractions as they arise. There is also a timed version of this version.
- Directory iterate_over_collection augments classes ArrayList[E] and HashTable[E] with iterators, and demonstrates that functionality.