SWE 619 In Class Exercise Number 6
October 17, 2017


This exercise is intended to get you to think about Liskov's argument about equals(). The following is "normal" Java:

Set<List<String>> s = new HashSet<List<String>>();     // AF(s) = ___
List<String> x = new ArrayList<String>();  // AF(x) = ___
List<String> y = new ArrayList<String>();  // AF(y) = ___
s.add(x);		 // AF(s) = ____
s.add(y);		 // AF(s) = ____
s.contains(y)            // true or false?
y.add("cat");	         // AF(y) = ____
                         // AF(s) = ____
s.contains(y);           // true or false?
s.add(y);		 // s.state = ____
y.remove("cat");	 // s.state = ____
Fill in the values.





Now, let's turn to element subtypes. How does Liskov's SumSet example (figure 8.8) work for the element subtype approach?



Now, let's turn to related subtypes.
  1. Define an implementation of Comparator that reverses the natural ordering.

    Does this implementation satisfy the Comparator contract?

    Can you generify this implementation?

  2. Repeat the exercise with a comparator<Integer> that uses absolute values.

  3. Repeat the exercise with a comparator<Integer> that orders evens before odds.