Consider this example:
public class SimpleValidator
{
public virtual bool InRange(int x)
{
return x >= 6 && x <=12;
}
}
public class OffsetAwareValidator : SimpleValidator
{
int offset = 0;
public OffsetAwareValidator(int offset)
{
this.offset = offset;
}
public override bool InRange(int x)
{
var num = x + offset;
return num >= 6 && num <= 12;
}
}
Now, obviously, new OffsetAwareValidator(0)
will have the exact same behavior as SimpleValidator. However, when offset is non zero, some values that pass validation in OffsetAwareValidator
would not pass it in SimpleValidator
.
Is this a violation of LSP?