8.3 Leveraging Python’s duck typing
When a design involves inheritance, there is often a clear relationship from a superclass to one or more subclasses. In the Choosing between inheritance and composition – the ”is-a” question recipe of this chapter, as well as the Extending a built-in collection – a list that does statistics recipe in Chapter 7, we’ve looked at extensions that involve a proper subclass-superclass relationship.
In order to have classes that can be used in place of one another (”polymorphic” classes), some languages require a common superclass. In many cases, the common class doesn’t have concrete implementations for all of the methods; it’s called an abstract superclass.
Python doesn’t require common superclasses. The standard library offers the abc module to support creating abstract classes in cases where it can help to clarify the relationships among classes...