Objects of a subclass should be usable wherever objects of their parent class are expected without altering the correctness of the program. Subclass methods must accept at least as broad parameter types and return at least as specific types as the parent, and must not strengthen preconditions or weaken postconditions.
Examples:
- A method
feed(Cat c)works with any cat. A subclass that overrides it asfeed(Animal c)is safe — it's more permissive. A subclass that restricts it tofeed(BengalCat c)violates LSP: passing a generic cat from client code now breaks the method, because the subclass is not a true substitute for its parent.
Synonyms: lsp