-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Modern Python Cookbook - Third Edition
By :
When we have a collection of objects with mixed types, we often need to distinguish among the types. When working with classes that we’ve defined, it’s possible to define classes that are properly polymorphic. This is not generally the case when working with Python’s internal objects, or working with collections of data that involve a mixture of classes we’ve defined, and built-in classes that are part of Python.
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 kind of design fits the ”L” design principle in the S.O.L.I.D design principles: the Liskov Substitution Principle. Any of the subclasses can be used in place of the superclass, because they all have a common set of method definitions. For more information on this, see Chapter 8.
...