Case Study: Immutable Finite Functions, Part 2
In this case study, we design and implement
an immutable abstract data type
of finite functions
that builds on our
AListWithKeyIterator<K,V>
example
to define a class that will implement the entire
java.util.Map<K,V>
interface.
The IMap<K,V>
interface
we define in this lesson extends
java.util.Map<K,V>
.
Our first implementation of the IMap<K,V>
reuses our implementation of
AListWithKeyIterator<K,V>
from the previous lesson by
composing
its association lists with classes
that add many new methods, most of them inherited from an
abstract base class defined in Java's java.util
package:
AbstractMap<K,V>
.
The
Map<K,V>
interface includes some operations that have side effects. Luckily for us, all of those side-effecting operations are optional. That means we can implement an ADT of immutable finite maps by arranging for all of the side-effecting methods of theMap<K,V>
interface to throw anUnsupportedOperationException
if those methods are ever called.
© Mitchell Wand, 2012-2015
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
The work has been modified by William D Clinger in these ways and more: conversion from PowerPoint to HTML, and from Racket to Java.