Parasitic Methods: An Implementation of Multi-Methods for Java

by John Boyland and Giuseppe Castagna

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 run-time classes of all the parameters, not just the receiver. Multi-methods permit intuitive and type-safe 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 multi-methods. 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.

BibTeX Style Reference

@inproceedings(boyland/castagna:97parasite,
  author =      {John Boyland and Giuseppe Castagna},
  title =       {Parasitic Methods: 
		 An Implementation of Multi-Methods for Java},
  booktitle = 	{Proceedings of OOPSLA '97: Object-Oriented
		 Programming Systems, Languages and Applications},
  pages = 	{66--76},
  month =       oct,
  year =        1997,
  publisher = 	"ACM Press",
  address = 	"New York",
  city = 	"Atlanta, GA",
  date = 	"Oct.\ 5--9",
  journal = 	"SIGPLAN Notices",
  volume = 	32,
  number = 	10
  )

How to Get a Copy

The paper has appeared in the OOPSLA '97 proceedings, The full text is available in the ACM Digital Library, but unfortunately this copy is an image (scanned in). ACM has declined my clean copy, and so I make it available here (and in PDF).


ACKNOWLEDGMENT OF SPONSORSHIP

Effort sponsored by the Defense Advanced Research Projects Agency, and Rome Laboratory, Air Force Materiel Command, USAF, under agreement number F30602-97-2-0241.

DISCLAIMER

The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the Defense Advanced Research Projects Agency, Rome Laboratory or the U.S. Government.


Last Modified: December 9, 2014

Parasitic Methods / boyland@cs.uwm.edu