Inheritance example: Playing Cards

Think back to our earlier Deck and Hand playing card classes. While there are obvious differences between decks of cards and hands of cards there are also similarities. Let's focus on the similarities for a moment.

OOP recommends that we remove this common functionality from both Deck and Hand to a separate base class and have our Deck and Hand classes inherit this functionality from it. This way if we need to modify some part of it, e.g. the card list representation, we get to do it in a single place and the changes will be automatically propagated to the descendant classes. It's a small win in a shallow hierarchy like this one, but it's a huge win when the hierarchy is deep because then we get to make a change in one place rather than dozens. Here's how this is done in Python.