Academia.eduAcademia.edu

Covariance and contravariance: con ict without a cause

1995

Abstract

In type-theoretic research on object-oriented programming, the issue of \covariance versus con-travariance " is a topic of continuing debate. In this short note we argue that covariance and con-travariance appropriately characterize two distinct and independent mechanisms. The so-called contravariance rule correctly captures the subtyping relation (that relationwhich establisheswhich sets of functions can replace another given set in every context). A covariant relation, instead, characterizes the specialization of code (i.e., the denition of new code which replaces old def-initions in some particular cases). Therefore, covariance and contravariance are not opposing views, but distinct concepts that each have their place in object-oriented systems. Both can (and should) be integrated in a type-safe manner in object-oriented languages. We also show that the independence of the two mechanisms is not characteristic of a particular model but is valid in general, since covariant spe...