5.2 Adding behaviors to class data with properties
Throughout this book, we’ve focused on the encapsulation of behavior and data. Often, there is a clear set of largely passive data objects, and generally active methods. In Python, the distinction between data and behavior is uncannily blurry.
It may not help to use platitudes such as think outside the box. Rather, the number of possibilities available suggests we need to stop thinking about the box.
Before we get into the details, let’s discuss some bad object-oriented design principles. In some languages, we’re advised to never access attributes directly. They insist that we write attribute access like this:
class Color:
def __init__(self, rgb_value: int, name: str) -> None:
self._rgb_value = rgb_value
self._name...