Python · Classes and Object Design · Intermediate · 26 min read
Python Composition, Protocols and Duck Typing: Designing with Has-A Instead of Is-A
Design flexible Python code without deep hierarchies. Learn why composition usually beats inheritance, how to delegate and inject collaborators, duck typing and the EAFP style, structural typing with typing.Protocol, the strategy and adapter patterns in Python, mixins and when they are acceptable, __getattr__ delegation, and a refactoring workflow from a class hierarchy to composed parts.
Create an account to start
Create a free account to see what this lesson covers
- Every free lesson in every section, in full
- Track your progress and pick up where you left off
- Free practice questions and an incident simulation
- Takes under a minute: name, email and a password
No card needed. Full access to Python is a paid upgrade you can choose later.