EMZETT.
Login

LSP

In short: The Liskov substitution principle (LSP) states: objects of a subclass must be usable anywhere in the same way as objects of the superclass.

In more detail: The “L” in SOLID. A subclass must not break the expectations placed on the superclass.

In Depth

Classic counter-example

A Square inherits from Rectangle. Anyone who sets width and height separately is surprised because with a square both must be equal. Inheritance is the wrong choice here.

Rules

No stricter preconditions, no weaker postconditions, no unexpected exceptions. See OCP, inheritance, override.

See also: SOLID-Prinzipien, OCP, Inheritance