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
}
Counter2
API?
Counter2
a valid subtype of Counter
?
Counter3
API?
Counter3
a valid subtype of Counter
?
In particular, does incr(int n)
have to be consistent with incr()
?