8.2 Separating concerns via multiple inheritance
In the Choosing between inheritance and composition – the ”is-a” question recipe earlier in the chapter, we looked at the idea of defining a Deck class that was a composition of playing card objects. For the purposes of that example, we treated each Card object as simply having rank and suit attributes. This created two small problems:
The display for the card always showed a numeric rank. We didn’t see J, Q, or K. Instead we saw 11, 12, and 13. Similarly, an ace was shown as 1 instead of A.
Many games like Cribbage assign a point value to each rank. Generally, the face cards have 10 points. The remaining cards have points that match their rank.
Python’s multiple inheritance lets us handle variations in card game rules while keeping a single, essential Card class. Using multiple inheritance lets us separate rules for specific games from generic properties...