Abstract Base Classes and Operator Overloading
We often need to make a distinction between concrete classes that have a complete set of attributes and methods, and an abstract class that is missing some details. This parallels the philosophical idea of abstraction as a way to summarize complexities. We might say that a sailboat and an airplane have a common, abstract relationship of being vehicles, but the details of how they move are distinct.
In Python, we have two approaches to defining similar things:
- Duck typing: When two class definitions have the same attributes and methods, then instances of the two classes have the same protocol and can be used interchangeably. We often say, "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck."
- Inheritance: When two class definitions have common aspects, a subclass can share common features of a superclass. The...