5 ms·
Somewhat related. The subclass relationship isn't very rigorous, you're free to have completely different behaviours out of the same methods in a subclass. Lisk
by codebje 3y ago
Somewhat related. The subclass relationship isn't very rigorous, you're free to have completely different behaviours out of the same methods in a subclass. Liskov says don't do that: if B is a subclass of A it should behave like an A.
When it comes to types, a subtype is one that can be transparently substituted for its super type. If S <: T, a term of type S can be used where a T was expected just fine. For union types, it's a given that T <: T|a for any type a, and a T will behave exactly like a T|a whose value is a T.
The Liskov principle states that a subclass should be a subtype.