SWE 619 In Class Exercise Number 5C
October 3, 2017


Consider the following:

public class Counter{   // Liskov 7.8
   public Counter()     //EFF: Makes this contain 0
   public int get()     //EFF: Returns the value of this
   public void incr()   //MOD: this //EFF: makes this larger
}
public class Counter2 extends Counter { // Liskov 7.9
   public Counter2()         //EFF: Makes this contain 0
   public void incr()       // MOD: this //EFF: double this
}
public class Counter3 extends Counter {  // Liskov 7.10
   public Counter3(int n)   //EFF: Makes this contain n
   public void incr(int n)  // MOD: this //EFF: if n>0 add n to this
}
  1. What role do constructors play in analyzing the Liskov Substitition Principle?
  2. Is there a constraint about negative/zero values for this? How do we know?
  3. What methods are in the Counter2 API?
  4. Is Counter2 a valid subtype of Counter?
  5. What methods are in the Counter3 API?
  6. Is Counter3 a valid subtype of Counter? In particular, does incr(int n) have to be consistent with incr()?