Summary, design considerations, and trade-offs
In this chapter, we looked at the essential ingredients of abstract base classes. We saw a few features of each kind of abstraction.
We also learned that one rule for good class design is to inherit as much as possible. We saw two broad patterns here. We also saw common exceptions to this rule.
Some application classes don't have behaviors that overlap with internal features of Python. From our Blackjack examples, a Card
isn't much like a number, a container, an iterator, or a context. It's just a playing card. In this case, we can generally invent a new class because there isn't any built-in features to inherit fro.
When we look at Hand
, however, we see that a hand is clearly a container. As we noted when looking at hand classes in Chapters 1, The __init__() Method, and Chapter 2, Integrating Seamlessly with Python – Basic Special Methods, the following are three fundamental design strategies:
Wrapping an existing container
Extending an existing...