Contravariant methods in Java and C++

  • Authors:
  • Cong-Cong Xing

  • Affiliations:
  • Nicholls State University, Thibodaux, LA

  • Venue:
  • Journal of Computing Sciences in Colleges
  • Year:
  • 2006

Quantified Score

Hi-index 0.00

Visualization

Abstract

The impact of contravariant methods (and/or binary methods) on the relationship between object subtyping and inheritance has been extensively studied, in theory, in the research of object-oriented programming (OOP). It has been found that subtyping induced by inheritance is not sound when contravariant methods (andor binary methods) are present in objects. Unfortunately, in the practice of OOP, it seems that this important discovery in OOP theory has not been taken into account to improve the programming activities. As a result, strange and ad hoc computations can occur when contravariant methods are involved in programming. In this short paper, we first describe the contravariant methods problem using ζ-calculus. Then, we show how this problem is handled in practice by presenting the corresponding Java code and C++ code of the problem. Finally, through a comparison between the theory and practice of OOP, we would like to point out that fundamental bugs exist in the way in which inheritance, subtyping, and dynamic binding are dealt with in Java and C++; that more theoretical work needs to be done to precisely describe the relationship between inheritance and subtyping; and that corrections and improvements in OOP practice, under the guidance of OOP theory, need to be implemented properly.