3 ms·
Obviously modelling your program like Car extends Vehicle is bad, but thinking in terms of real-life relations makes thinking about complex subtyping relations
by nmilo 4y ago
Obviously modelling your program like Car extends Vehicle is bad, but thinking in terms of real-life relations makes thinking about complex subtyping relations like covariance much easier to grasp.
Compare:
> If B and C are subtypes of A, then List<T> must be invariant over T since List<B> should not be a subtype of List<A>, which can contain both B and C.
with:
> List<Cat> can't become List<Animal>, because you might add Dogs to that list!