Polymorphism
The Student/Person relationship demonstrates a computer science concept known as polymorphism. In brief, polymorphism is a programming languages ability to treat an object differently based on context.
A OboePlayer is of course a OboePlayer, but it is also a Person. Because it derives from Person, you could use a OboePlayer object anywhere you’d use a Person object.
This example demonstrates how you can treat a OboePlayer as a Person:
func phonebookName(_ person: Person) -> String { return "(person.lastName), (person.firstName)"
}
let person = Person(firstName: "Johnny", lastName: "Appleseed")
let oboePlayer = OboePlayer(firstName: "Jane", lastName: "Appleseed")
phonebookName(person) // Appleseed, Johnny phonebookName(oboePlayer) // Appleseed, Jane
Because OboePlayer derives from Person, it is a valid input into the function phonebookName(:). More importantly, the function has no idea that the object passed in is anything _other than a regular Person. It can only observe the elements of OboePlayer that are defined in the Person base class.
With the polymorphism characteristics provided by class inheritance, Swift is treating the object pointed to by oboePlayer differently based on the context. This can be particularly useful to you when you have diverging class hierarchies, but want to have code that operates on a common type or base class.