Next Previous Up Top

4 Class Relationships

4.11 Summary

4.11 Summary

This chapter has introduced two kinds of class relationship: association and inheritance. Association is where objects of one class make use of objects of another, while inheritance allows a subclass to be an extension of a superclass. Inheritance interacts with dynamic binding to allow subclass objects to be used when a superclass type is specified, providing substitutability of objects, a form of polymorphism. Substitutability in turn relies on the use of carefully defined public interfaces described by collections of public methods. This idea is sufficiently important that Java provides interface declarations to allow interfaces to be declared independently of both classes and inheritance, providing a type conformance mechanism to augment the basic type system.

Using association and inheritance, a program can be constructed by first identifying the classes and interfaces required and then determining how they are related. The resulting set of classes, interfaces and relationships gives the structure of the program, tying all its parts together. Identifying the correct relationships is a key part of the programming process and avoiding mistakes here will be very important to the overall quality of the program.

Copyright 1997 Russel Winder and Graham Roberts

Last updated: 6 Oct 1997