SWE 619 In Class Exercise Number 5A


Goal: Understanding dynamic dispatching:

Consider Liskov's MaxIntSet example with explict repOk() calls: (Really, we'd need assertions on these calls...)

   public class IntSet {
      public void insert(int x) {...; repOk();}
      public void remove(int x) {...; repOk();}
      public boolean repOk() {...}
   }
   public class MaxIntSet extends IntSet {
      public void insert(int x) {...; super.insert(x); repOk();}
      public void remove(int x) {super.remove(x); ...; repOk();}
      public boolean repOk() {super.repOk(); ...;}
   }

    MaxIntSet s = {3, 5}; s.remove(5);  // repOk()????

  1. What does the default constructor in MaxIntSet do?
  2. What do the "..." bits do?
  3. How does the call work out?
  4. What is the abstract state of a MaxIntSet? There are two options. What are they, and what are the consequences of each choice?