Parasitic methods

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.

This publication has 6 references indexed in Scilit: