Subtyping
Subtyping is a relation between types in a programming language where one type, called a subtype, is considered a more specific version of another type, its supertype. Values of the subtype can be used wherever a value of the supertype is expected, without altering the program’s correctness. Subtyping enables polymorphism and code reuse by allowing operations to be written in terms of the supertype and applied to any of its subtypes.
The relationship is often described in terms of substitutability. The Liskov Substitution Principle specifies that objects
Subtyping systems can be nominal or structural. In nominal typing, subtyping is declared explicitly through inheritance
Subtyping interacts closely with generics and variance. Variance describes how subtyping relates to type parameters: covariant,
Common considerations include coercions and upcasts, where values are treated as their supertype, and the potential