Suppose I have two unrelated interfaces with the same method:
interface Table { /** * @param width (0 < width <= 100) */ void setWidth(int width); } interface Square { /** * @param width (50 <= width <= 10000) */ void setWidth(int width); } Then I create a class which implements both of these interfaces:
class SquareTable implements Square, Table { void setWidth(int width) { precondition = ... if (!precondition) throw new PreconditionFailedException("Precondition failed: ..."); } } How precondition expressions should be combined to satisfy Liskov substitution principle? Should they and'ed or or'ed? I.e. what should be written instead of ...:
width > 0 && width <= 10000 // using OR width >= 50 && width <= 100 // using AND And which rule should be used for postconditions?
interface Table { /** * @return width (0 < width <= 100) */ int getWidth(); } interface Square { /** * @return width (50 <= width <= 10000) */ int getWidth(); } class SquareTable implements Square, Table { int getWidth() { postcondition = ... if (!postcondition) throw new PostconditionFailedException("Postcondition failed: ..."); } } width > 0 && width <= 10000 // using OR width >= 50 && width <= 100 // using AND