-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Modern Python Cookbook - Third Edition
By :
One important reason for defining a collection of closely-related types is to distinguish the processing that applies to the objects. One technique for providing distinct behavior is by using a polymorphic design: a number of subclasses provide distinct implementations of a common function. When working entirely with our own classes, we can design them to have common methods and attributes, but offer distinct behavior depending on which of the subclasses is involved. This is covered in Chapter 8.
This is not generally possible when working with Python’s internal objects, or when working with collections of data that involve a mixture of classes we’ve defined, and built-in classes that are part of Python. In these cases, it’s simpler to rely on type matching to implement distinct behaviors. One approach was shown in the Using the built-in type matching functions recipe in this chapter.
We can also use...