Minimizing dependencies

When we design a class, we must also consider the network of dependencies around that class: classes on which it depends and classes that depend on it. In order to simplify testing a class definition, we need to isolate it from the surrounding classes. For more ideas on this, refer to Chapter 15, Design Principles and Patterns.

An example of this is the Deck class, which depends on the Card class. We can easily test Card in isolation, but when we want to test the Deck class, we need to tease it away from the definition of Card.

Here's one (of many) previous definition of Card that we've looked at:

import enumclass Suit(enum.Enum):    CLUB = "♣"    DIAMOND = "♦"    HEART = "♥"    SPADE = "♠"class Card:    def __init__(        self, rank: ...

Get Mastering Object-Oriented Python - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.