Book contents
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
4 - Relationships between Classes
from PART ONE - FOUNDATIONS
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
Summary
We examine two important types of relationships between classes in this chapter – namely, composition and inheritance. We illustrate the concepts by constructing a complete software system in Java that illustrates the use of these two types of relationships.
Inheritance
Inheritance, as the name implies, involves the transmittal of behavioral characteristics from parent class to child class. Through inheritance one can establish behavior in a base class that is available and directly usable in a hierarchy of descendent classes that extend the base class.
As discussed in Chapter 1, inheritance can be centered on factoring and reusing methods (implementation inheritance) or on extending behavior (behavioral inheritance). It is the latter that we shall utilize in this chapter and throughout this book.
With behavioral inheritance, it is essential that any child class logically be of the same type as its parent. As you recall from Chapter 1, the principle of polymorphic substitution allows a descendent class to be used in place of its ancestor. This would make sense only if each child class can logically be considered to be a kind of its parent.
A child class may extend a parent class by introducing one or more fields or methods not found in the parent or by redefining one or more parent class methods.
- Type
- Chapter
- Information
- Fundamentals of OOP and Data Structures in Java , pp. 64 - 76Publisher: Cambridge University PressPrint publication year: 2000