Featherweight Jigsaw - Replacing inheritance by composition in Java-like languages

  • Authors:
  • Giovanni Lagorio;Marco Servetto;Elena Zucca

  • Affiliations:
  • DISI, University of Genova, v. Dodecaneso 35, 16146 Genova, Italy;DISI, University of Genova, v. Dodecaneso 35, 16146 Genova, Italy;DISI, University of Genova, v. Dodecaneso 35, 16146 Genova, Italy

  • Venue:
  • Information and Computation
  • Year:
  • 2012

Quantified Score

Hi-index 0.00

Visualization

Abstract

We present FJig, a simple calculus where basic building blocks are classes in the style of Featherweight Java, declaring fields, methods and one constructor. However, inheritance has been generalized to the much more flexible notion originally proposed in Bracha@?s Jigsaw framework. That is, classes play also the role of modules, that can be composed by a rich set of operators, all of which can be expressed by a minimal core. Fields and methods can be declared of four different kinds (abstract, virtual, frozen, local) determining how they are affected by the operators. We keep the nominal approach of Java-like languages, that is, types are class names. However, a class is not necessarily a structural subtype of any class used in its defining expression. While this allows a more flexible reuse, it may prevent the (generalized) inheritance relation from being a subtyping relation. So, the required subtyping relations among classes are declared by the programmer and checked by the type system. The calculus allows the encoding of a large variety of different mechanisms for software composition in class-based languages, including standard inheritance, mixin classes, traits and hiding. Hence, FJig can be used as a unifying framework for analyzing existing mechanisms and proposing new extensions. We provide two different semantics of an FJig program: flattening and direct semantics. The difference is analogous to that between two intuitive models to understand inheritance: the former where inherited methods are copied into heir classes, and the latter where member lookup is performed by ascending the inheritance chain. Here we address equivalence of these two views for a more sophisticated composition mechanism.