The following C++ code establishes an explicit inheritance relationship between classes B and A, where B is both a subclass and a subtype of A, and can be used as an A wherever a B is specified (via a reference, a pointer or the object itself).
[3] The following python code establishes an explicit inheritance relationship between classes B and A, where B is both a subclass and a subtype of A, and can be used as an A wherever a B is required.
When defining an interface, PayloadList, that associates an optional value of generic type P with each element, its declaration might look like: The following parameterizations of PayloadList are subtypes of List
However, this violates LSP even though the is-a relationship holds between Rectangle and Square Consider the following example, where function g does not work if a Square is passed in, and so the open-closed principle might be considered to have been violated.
Conversely, if one considers that the type of a shape should only be a constraint on the relationship of its dimensions, then it is the assumption in g() that SetHeight will change height, and area, but not width that is invalid, not just for true squares, but even potentially for other rectangles that might be coded so as to preserve area or aspect ratio when height changes.