Member-only story
An Introduction to Object Oriented Inheritance
Inheritance is a type of object-oriented design that is used to create a new class using attributes of an existing class. In these instances, we refer to the existing class as the base class and the new class as the derived class. Inheritance is valuable for instances where we have many similar objects that share properties, but also have properties unique to the object itself.
Suppose you were designing a system to track information about employees at a company. At this company, you have hourly employees, salaried employees, managers, and executives. When we think about the attributes of each of these employees, we realize that they have a lot in common. Every employee, regardless of their employment type, will have a name, age, and employee ID, for instance. If we apply inheritance, we can implement a lot of these properties without needing to repeat code for every object. To do this, we start by defining a base class that each class will derive from. I will call this class Employee, and it will store properties for name, age, and employee ID.
The base class lays out the methods and properties that will be used by the derived classes. In this case, all the employees have a name, age, and employee ID, so we implement those properties and provide ways to access them. When we have a property that is unique to a specific type of employee…