There are three exercises in this lab. It allows one to extend the capabilities of objects while reusing code that is already written.
Some problems can arise, however, unless one follows the tenets of substitutability .
Today we are interested in extending the capabilities of the Java SDK defined HashMap to be able to associate multiple values with a single key. We are going to do this in two ways, and both will implement MultiMap . First, we will subclass HashMap to create MultiHashMap . To introduce the ability to store multiple elements while leaving the contracts for existing methods the same we will create two new methods, getAll and putAll, and override any methods necessary to implement the ability to map multiple values. Our method of doing this will be to let the superclass HashMap maintain a mapping from a key to a collection of values, rather than the actual values that are requested.