O'Reilly logo

Program Development in Java: Abstraction, Specification, and Object-Oriented Design by John Guttag, Barbara Liskov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8 Polymorphic Abstractions

In the preceding chapters, we have defined a number of collection types in which all elements of the collection are ints. Such collections are rather limiting. For example, suppose we wanted a set that contained Strings. We would not be able to use our implementation of IntSet for this purpose. Instead, we would need to provide a separate implementation for a StringSet. And if we later discovered the need for a set of characters, we would need yet another new implementation.

Having to define a new version of a collection abstraction each time we need to store a different type of element is not very satisfactory. Instead, it would be better to define the collection type just once yet have it work for all types of elements. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required