Inheritance
Inheritance was defined in Chapter 1 as a system in which children inherit attributes and behavior from a parent class. However, there is more to inheritance, and in this chapter we will explore inheritance in greater detail.
Chapter 1 states that you can determine an inheritance relationship by following a simple rule: If Class B is a Class A, then this is a good candidate for inheritance.
Is-a
One of the primary rules of OO design is that public inheritance is represented by an is-a relationship. Let's revisit the mammal example used in Chapter 1. To present a very simple example, let's concentrate on a Dog class. A dog has several behaviors that make it distinctly a dog, as opposed to a cat. For this example, let's specify two: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access