Parasitic methods: an implementation of multi-methods for Java

  • Authors:
  • John Boyland;Giuseppe Castagna

  • Affiliations:
  • Computer Science Department, Carnegie Mellon University, 5000 Forbes Avenue, Pittsburgh, PA;CNRS, LIENS, École Normale Supérieure, 45 rue d'Ulm, 75005 Paris, France

  • Venue:
  • Proceedings of the 12th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications
  • Year:
  • 1997

Quantified Score

Hi-index 0.00

Visualization

Abstract

In an object-oriented programming language, method selection is (usually) done at run-time using the class of the receiver. Some object-oriented languages (such as CLOS) have multi-methods which comprise several methods selected on the basis of the runtime classes of all the parameters, not just the receiver. Multi-methods permit intuitive and typesafe definition of binary methods such as structural equality, set inclusion and matrix multiplication, just to name a few. Java as currently defined does not support multimethods. This paper defines a simple extension to Java that enables the writing of "encapsulated" multi-methods through the use of parasitic methods, methods that "attach" themselves to other methods. Encapsulated multi-methods avoid some of the modularity problems that, arise with fully general multi-methods. Furthermore, this. extension yields for free both covariant and contravariant specialization of methods (besides Java's current invariant specialization).Programs using this extension. can be translated automatically at the source level into programs that do not; they are modular, type-safe, and allow separate compilation.