Delegation by object composition

  • Authors:
  • Lorenzo Bettini;Viviana Bono;Betti Venneri

  • Affiliations:
  • Dipartimento di Informatica, Università di Torino, Italy;Dipartimento di Informatica, Università di Torino, Italy;Dipartimento di Sistemi e Informatica, Università di Firenze, Italy

  • Venue:
  • Science of Computer Programming
  • Year:
  • 2011

Quantified Score

Hi-index 0.00

Visualization

Abstract

Class inheritance and method overriding, as provided by standard class-based languages, are often not flexible enough to represent objects with some dynamic behavior. In this respect, object composition equipped with different forms of method body lookup is often advocated as a more flexible alternative to class inheritance since it takes place at run time, thus permitting the behavior of objects to be specialized dynamically. In this paper, we illustrate Incomplete Featherweight Java (IFJ), an extension of Featherweight Java with a novel linguistic construct, the incomplete object. Incomplete objects require some missing methods which can be provided at run time by composition with another (complete) object. Furthermore, we present two mechanisms for the method body lookup on (composed) objects, one based on delegation and the other based on consultation. Thanks to the design of the language, the consultation-based lookup is a simple extension of the delegation-based one. Both mechanisms are disciplined by static typing, therefore the language enjoys type safety (which implies no ''message-not-understood'' run-time errors) and avoids possible accidental overrides due to method name clashes.