Half & Half: Multiple Dispatch and Retroactive Abstraction for Java TM Gerald Baumgartner * Martin Jansche ** Konstantin L¨ aufer *** * Dept. of Computer and Information Science The Ohio State University Columbus, OH 43210 gb@cis.ohio-state.edu ** Dept. of Linguistics The Ohio State University Columbus, OH 43210 jansche.1@osu.edu *** Dept. of Computer Science Loyola University of Chicago Chicago, IL 60626 laufer@cs.luc.edu March 23, 2002 Technical Report OSU-CISRC-5/01-TR08, Revised 3/02 Abstract Software often goes through a variety of extensions during its lifetime: adding new fields or new variants to a data structure, retroactively creating new type abstractions, and adding new operations on a data structure. As characterized by the extensibility problem, it should be possible to apply any combination of these types of extensions in any order. Mainstream object-oriented languages, however, do not well support the latter two. This paper proposes two language mechanisms that facilitate extending existing type hierarchies: multimethod dispatch and retroactive abstraction. For these two mechanisms to coexist, it is necessary to allow method dispatch on parameters of interface types, which presents problems with static type-checking. We present a type-safe solution that combines the two mechanisms by limiting multimethod type checks to package boundaries and by compiling certain packages with multimethods into sealed Jar files. 1 Introduction As software evolves, data structures might have to be extended along several dimensions. The nature of these exten- sions often cannot be foreseen at the design stage. Without appropriate support of the programming language and in the design of the software, simple extensions might require large amounts of existing code to be modified. Suppose we are writing a compiler for a language the size of Java, where the data structure for representing the parse trees consists of 100 variants. If the compiler is written in an object-oriented style, we would represent this data structure as a class hierarchy with 100 classes. If later changes require adding additional information to certain parse tree nodes or adding new variants, the object-oriented style would make this straightforward by adding fields and Java is a registered trademark of Sun Microsystems, Inc. 1