From the course: Programming Foundations: Object-Oriented Design
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Inheritance - Python Tutorial
From the course: Programming Foundations: Object-Oriented Design
Inheritance
When I need to create a new class it may not always be necessary to build it from scratch. If my program has an existing class that's similar to what I need, then I can use inheritance to base my new class on that existing one. Inheritance enables a new class to receive or inherit the attributes and methods of existing classes using the same implementation which is a great form of code reuse. Let's say for example I want to model the characters present in a bakery. I might start by defining a class for customers, which has attributes for the customer's name, phone number, email address, and a customer ID number. Additionally I give that customer class a method to update their contact information, and a method to purchase items. The bakery also has employees so I create an employee class with attributes for the employee's name, phone number, email address, and employee ID number. The employee can update their contact…