Type Hierarchy

  • Express the power of constructing type hierarchies.
  • Arrange simple types into a type hierarchy.

Classes allow us to define our data types. Indeed, Student and GradStudent are data types. More specifically, GradStudent is a subtype of Student. And by the same token, Student is the base type of GradStudent.

Since inheritance is transitive, it allows us to create a hierarchy of types. This makes object-oriented programming an instrumental paradigm for real-world modeling because the entities in real-world problems often naturally exhibit such a hierarchy.

Example: Fruits
Example: Animals

Exercise We are building a software solution for a banking system. We have the following classes so far: Account, Checking, Saving, Debit, Credit. Arrange these classes into the following type hierarchy.

Solution