Michael G Schwern wrote:

> How exactly does one "weaken" a precondition?

Say I define a mathematical mod() function in my parent number class.

precondition: $a > 0, $b > 0, $b is int
mod( $a, $b )

Then in my subclass, I want to make it work in a wider variety of
contexts. I change the definition to:

precondition: $b is int, $b != 0
mod( $a, $b )

It now properly supports modulo arithmetic for negative numbers, because
the requirements for running the function have been weakened. It is still
completely substitutable anywhere that the parent implementation would
work, but if code is dealing with my subclass it is allowed to work with
the weakened precondition.

Since your proposal was based upon the idea of having every parent
condition apply to child implementations, the possibility for strengthened
postconditions falls out of the proposal nicely. But since preconditions
work in the opposite direction, they don't quite gel with that particular
proposal.

Mike Lambert


Reply via email to