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()????
MaxIntSet
do?
MaxIntSet
?
There are two options.
What are they, and what are the consequences of each choice?