Safer typing of complex API usage through Java generics

W. Harrison, D. Lievens, F. Simeoni

Research output: Chapter in Book/Report/Conference proceedingConference contribution book

1 Citation (Scopus)
51 Downloads (Pure)

Abstract

When several incompatible implementations of a single API are in use in a Java program, the danger exists that instances from different implementations may inadvertently be mixed, leading to errors. In this paper we show how to use generics to prevent such mixing. The core idea of the approach is to add a type parameter to the interfaces of the API, and tie the classes that make up an implementation to a unique choice of type parameter. In this way methods of the API can only be invoked with arguments that belong to the same implementation. We show that the presence of a type parameter in the interfaces does not violate the principle of interface-based programming: clients can still completely abstract over the choice of implementation. In addition, we demonstrate how code can be reused between different implementations, how implementations can be defined as extensions of other implementations, and how different implementations may be mixed in a controlled and safe manner. To explore the feasibility of the approach, gauge its usability, and identify any issues that may crop up in practical usage, we have refactored a fairly large existing API-based application suite, and we report on the experience gained in the process.
Original languageEnglish
Title of host publicationPPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java
Pages67-75
Number of pages9
DOIs
Publication statusPublished - 2009

Fingerprint

Application programming interfaces (API)
Interfaces (computer)
Gages
Crops

Keywords

  • programming
  • java programming
  • application programming interface

Cite this

Harrison, W., Lievens, D., & Simeoni, F. (2009). Safer typing of complex API usage through Java generics. In PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java (pp. 67-75) https://doi.org/10.1145/1596655.1596666
Harrison, W. ; Lievens, D. ; Simeoni, F. / Safer typing of complex API usage through Java generics. PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java. 2009. pp. 67-75
@inproceedings{8a9b82ba1e9e427b8e64a9ebae185a26,
title = "Safer typing of complex API usage through Java generics",
abstract = "When several incompatible implementations of a single API are in use in a Java program, the danger exists that instances from different implementations may inadvertently be mixed, leading to errors. In this paper we show how to use generics to prevent such mixing. The core idea of the approach is to add a type parameter to the interfaces of the API, and tie the classes that make up an implementation to a unique choice of type parameter. In this way methods of the API can only be invoked with arguments that belong to the same implementation. We show that the presence of a type parameter in the interfaces does not violate the principle of interface-based programming: clients can still completely abstract over the choice of implementation. In addition, we demonstrate how code can be reused between different implementations, how implementations can be defined as extensions of other implementations, and how different implementations may be mixed in a controlled and safe manner. To explore the feasibility of the approach, gauge its usability, and identify any issues that may crop up in practical usage, we have refactored a fairly large existing API-based application suite, and we report on the experience gained in the process.",
keywords = "programming, java programming, application programming interface",
author = "W. Harrison and D. Lievens and F. Simeoni",
year = "2009",
doi = "10.1145/1596655.1596666",
language = "English",
pages = "67--75",
booktitle = "PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java",

}

Harrison, W, Lievens, D & Simeoni, F 2009, Safer typing of complex API usage through Java generics. in PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java. pp. 67-75. https://doi.org/10.1145/1596655.1596666

Safer typing of complex API usage through Java generics. / Harrison, W.; Lievens, D.; Simeoni, F.

PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java. 2009. p. 67-75.

Research output: Chapter in Book/Report/Conference proceedingConference contribution book

TY - GEN

T1 - Safer typing of complex API usage through Java generics

AU - Harrison, W.

AU - Lievens, D.

AU - Simeoni, F.

PY - 2009

Y1 - 2009

N2 - When several incompatible implementations of a single API are in use in a Java program, the danger exists that instances from different implementations may inadvertently be mixed, leading to errors. In this paper we show how to use generics to prevent such mixing. The core idea of the approach is to add a type parameter to the interfaces of the API, and tie the classes that make up an implementation to a unique choice of type parameter. In this way methods of the API can only be invoked with arguments that belong to the same implementation. We show that the presence of a type parameter in the interfaces does not violate the principle of interface-based programming: clients can still completely abstract over the choice of implementation. In addition, we demonstrate how code can be reused between different implementations, how implementations can be defined as extensions of other implementations, and how different implementations may be mixed in a controlled and safe manner. To explore the feasibility of the approach, gauge its usability, and identify any issues that may crop up in practical usage, we have refactored a fairly large existing API-based application suite, and we report on the experience gained in the process.

AB - When several incompatible implementations of a single API are in use in a Java program, the danger exists that instances from different implementations may inadvertently be mixed, leading to errors. In this paper we show how to use generics to prevent such mixing. The core idea of the approach is to add a type parameter to the interfaces of the API, and tie the classes that make up an implementation to a unique choice of type parameter. In this way methods of the API can only be invoked with arguments that belong to the same implementation. We show that the presence of a type parameter in the interfaces does not violate the principle of interface-based programming: clients can still completely abstract over the choice of implementation. In addition, we demonstrate how code can be reused between different implementations, how implementations can be defined as extensions of other implementations, and how different implementations may be mixed in a controlled and safe manner. To explore the feasibility of the approach, gauge its usability, and identify any issues that may crop up in practical usage, we have refactored a fairly large existing API-based application suite, and we report on the experience gained in the process.

KW - programming

KW - java programming

KW - application programming interface

UR - http://portal.acm.org/ft_gateway.cfm?id=1509281&type=pdf&coll=Portal&dl=GUIDE&CFID=76298374&CFTOKEN=30615543

U2 - 10.1145/1596655.1596666

DO - 10.1145/1596655.1596666

M3 - Conference contribution book

SP - 67

EP - 75

BT - PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java

ER -

Harrison W, Lievens D, Simeoni F. Safer typing of complex API usage through Java generics. In PPPJ '09: Proceedings of the 7th International Conference on Principles and Practice of Programming in Java. 2009. p. 67-75 https://doi.org/10.1145/1596655.1596666