Introduction
In Chapter 6, Basics of Classes and Objects, we looked at some recipes that cover the basics of class design. In this chapter, we'll dive a little more deeply into Python classes.
In the Designing classes with lots of processing and Using properties for lazy attributes recipes in Chapter 6, Basics of Classes and Objects, we identified a design choice that's central to object-oriented programming, the wrap versus extend choice. It's possible to add features to a class via extension and it's also possible to create a new class that wraps an existing class to add new features. There are a number of extension techniques available in Python, providing a lot of alternatives.
A Python class can inherit features from more than one superclass. This can lead to confusion, but a simple design pattern, the mixin, can prevent problems.
A larger application may require some global data that's widely shared by many classes or modules. This can be challenging to manage. We can, however, use a...