Parasitic methods
- 9 October 1997
- journal article
- Published by Association for Computing Machinery (ACM) in ACM SIGPLAN Notices
- Vol. 32 (10) , 66-76
- https://doi.org/10.1145/263700.263721
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:
- Pizza into JavaPublished by Association for Computing Machinery (ACM) ,1997
- Parameterized types for JavaPublished by Association for Computing Machinery (ACM) ,1997
- Java is type safe — ProbablyPublished by Springer Nature ,1997
- Typechecking and modules for multimethodsACM Transactions on Programming Languages and Systems, 1995
- A Calculus for Overloaded Functions with SubtypingInformation and Computation, 1995
- Static type checking of multi-methodsPublished by Association for Computing Machinery (ACM) ,1991