Quick Index
Overview
We have previously learned about the Has-a test to help identify a component relationship. We have a similar test called "is-a" to test for class inheritance.
Is a Shape? (yes)
Let's run an "is-a" test on Rectangle, RightTriangle and Circle:
- Rectangle is a Shape
- RightTriangle is a Shape
- Circle is a Shape
The "is-a" test sounds reasonable in each of these three cases.
Therefore we will consider adding a general class "Shape" as a superclass (see diagram in previous section).
Therefore we will consider" having these three classes inherit from a class "Shape".
Is a Shape? (no)
- Student is a Shape
- Person is a Shape
The "is-a" test does not sound reasonable for these two cases (e.g. "Student" is-a "Shape" does not make sense).
Therefore we will not consider having these two classes inherit from a class "Shape">