Type Invariance, Covariance & Contravariance October, 2006
In OOP, type variance refers to the difference between a class and its descendant or ascendant. For example lets say we have three classes; Vehicle, Spacecraft and Shuttle. Shuttle inherits from Spacecraft which inherits from Vehicle. They all vary by type. Vehicle is the contravariant of Spacecraft since Vehicle is Spacecraft's ancestor whereas Shuttle is the covariant of Spacecraft since Shuttle is a descendant of Spacecraft. Invariance simply refers to a lack of variance. For example a parameter or return type that must be invariant cannot respectively accept or return an ancestor or descendant of the type specified, they can only accept or return the specified type.