Comparison
Liskov substitution principlevsRefused bequest
Liskov substitution principle
the subclass threw on a method the parent promised, and every caller written against the parent was suddenly wrong.
The rule that an instance of a subtype must be usable anywhere the supertype is, without the caller having to know. Violations are easy to spot once you know the shape: a subclass that strengthens a precondition, weakens a guarantee, or throws where the parent returned. The square-and-rectangle example is the standard illustration, but the version you meet in real code is a read-only collection that inherits from a mutable one.
Full entry →Refused bequest
the subclass overrides three inherited methods to throw, because it never wanted them in the first place.
A subclass that inherits behaviour it does not want and rejects it, usually by overriding to do nothing or to raise. It is a Liskov substitution violation with a name: callers holding the parent type will call those methods and get a failure the type system promised could not happen. The fix is nearly always composition, or extracting the genuinely shared part into a smaller interface.
Full entry →