From the course: Advanced Python: Build Hands-On Projects with Design Patterns
Unlock this course with a free trial
Join today to access over 23,200 courses taught by industry experts.
Inheritance and polymorphism - Python Tutorial
From the course: Advanced Python: Build Hands-On Projects with Design Patterns
Inheritance and polymorphism
- [Instructor] Inheritance and polymorphism are key concepts that help you understand how design patterns work. Let's get started with inheritance. Inheritance establishes relationships between two classes as a parent and a child. The child class keeps all the attributes and methods of its parent. It can also add new attributes or methods of its own to the parent class definition. The child class can override the existing methods of its parent. Let's say that we have a pet class with two child classes; dog and cat. These child classes share a common attribute, the name they're inheriting from their parent class, pet. However, the child classes override the speak method in their definition. The dog class overrides its speak method to produce the barking sound, while the cat class overrides the same method to create the meow sound. Another object oriented class concept important to understand is polymorphism.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.