25-Comp-B11 Advanced Software Design · May 2016
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Yes, this is acceptable. Under LSP (Question 11), a subclass invariant is safe precisely when it is formed by CONJOINING (adding clauses to) the inherited invariant rather than replacing or weakening it — conjunction can only narrow, never broaden, the set of states an instance may occupy, so a B instance can never violate anything A's clients rely on.
Class B's full invariant is therefore the inherited clause AND the new clause: (x ≥ 0 AND y = 0) AND (x ≥ 0 implies y ≥ 0). Because A's own clause already forces y = 0 whenever an instance exists, the added clause x ≥ 0 implies y ≥ 0 reduces, for every state A already allows, to "if x ≥ 0 then 0 ≥ 0" — which is trivially true. The new clause is therefore logically REDUNDANT: it is automatically satisfied by every state A's invariant already permits, so B's combined invariant defines EXACTLY the same set of valid states as A's invariant alone. No new states are admitted, and none of A's forbidden states become reachable, so B trivially satisfies LSP's invariant-preservation requirement.
This is confirmed by exhaustive enumeration over integer x, y in a bounded range: every (x, y) pair satisfying A's invariant also satisfies B's added clause, and B's combined invariant is set-equal to A's invariant over the tested range.
Contrast with what would NOT be acceptable. If B had instead REPLACED A's y = 0 clause with the strictly weaker x ≥ 0 implies y ≥ 0 (dropping the original clause rather than adding to it), this WOULD violate LSP: it would newly admit states such as x = 3, y = 7 that A's invariant explicitly forbade. Any client code written against A, relying on y always being exactly 0, would then break when a B instance is substituted for an A reference — the textbook LSP violation. The distinguishing factor is not the new clause's content in isolation, but whether it is ADDED to (safe) or REPLACES (unsafe) the inherited invariant.