Inheritance and Composition: A Python OOP Guide (Summary)
You explored inheritance and composition in Python. You learned about the type of relationships that inheritance and composition create. You also went through a series of exercises to understand how inheritance and composition are implemented in Python.
In this course, you learned how to:
- Use inheritance to express an is a relationship between two classes
- Evaluate if inheritance is the right relationship
- Use multiple inheritance in Python and evaluate Python’s MRO to troubleshoot multiple inheritance problems
- Extend classes with mixins and reuse their implementation
- Use composition to express a has a relationship between two classes
- Provide flexible designs using composition
- Reuse existing code through policy design based on composition
Here are some books and articles that further explore object oriented design and can be useful to help you understand the correct use of inheritance and composition in Python or other languages:
- Design Patterns: Elements of Reusable Object-Oriented Software
- Head First Design Patterns: A Brain-Friendly Guide
- Clean Code: A Handbook of Agile Software Craftsmanship
- SOLID Principles
- Liskov Substitution Principle
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00 In this course, you learned how to create classes that inherit from one another, design basic class hierarchies with UML diagrams, use interfaces and abstract classes, use multiple inheritance and understand its drawbacks, build complex classes with composition, and change run-time behavior with composition.
00:26 You also got a glimpse at some common design patterns, like policy-based design and the factory pattern. At the same time, you practiced designing, redesigning, and building upon a nontrivial software project, which is definitely something to be proud of.
00:46 If you’re interested in learning more, I’ve included some links to books and articles in the video notes down below. These will teach you about object-oriented design and you’ll learn about new ways to use inheritance and composition.
Become a Member to join the conversation.