Safely creating correct subclasses without seeing superclass code

  • Authors:
  • Clyde Ruby;Gary T. Leavens

  • Affiliations:
  • Department of Computer Science, Iowa State University, 226 Atanasoff Hall, Ames, IA;Department of Computer Science, Iowa State University, 226 Atanasoff Hall, Ames, IA

  • Venue:
  • OOPSLA '00 Proceedings of the 15th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications
  • Year:
  • 2000

Quantified Score

Hi-index 0.00

Visualization

Abstract

A major problem for object-oriented frameworks and class libraries is how to provide enough information about a superclass, so programmers can safely create new subclasses without giving away the superclass's code. Code inherited from the superclass can call down to methods of the subclass, which may cause nontermination or unexpected behavior. We describe a reasoning technique that allows programmers, who have no access to the code of the superclass, to determine both how to safely override the superclass's methods and when it is safe to call them. The technique consists of a set of rules and some new forms of specification. Part of the specification would be generated automatically by a tool, a prototype of which is planned for the formal specification language JML. We give an example to show the kinds of problems caused by method overrides and how our technique can be used to avoid them. We also argue why the technique is sound and give guidelines for library providers and programmers that greatly simplify reasoning about how to avoid problems caused by method overrides.