7 Type Hierarchy

This chapter discusses a way to enhance the utility of data abstraction by defining families of related types. All members of a family have similar behavior: they all have certain methods, and calls on those methods behave in similar ways. Family members may differ by extending the behavior of the common methods or by providing additional methods.

A type family might correspond to the kind of hierarchy found in the real world; for example, Busses and Cars are both specialized kinds of Vehicles, or Dogs and Cats are special kinds of Mammals. Or it might correspond to concepts that only exist within programs; for example, a BufferedReader is a specialized kind of Reader.

A type family is defined by a type hierarchy (see Sidebar ...

Get Program Development in Java: Abstraction, Specification, and Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.