Book Image

Mastering Object-oriented Python

By : Steven F. Lott, Steven F. Lott
Book Image

Mastering Object-oriented Python

By: Steven F. Lott, Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

Summary


In this chapter, we looked at a number of built-in class definitions. The built-in collections are the starting place for most design work. We'll often start with tuple, list, dict, or set. We can leverage the extension to tuple, created by namedtuple(), for an application's immutable objects.

Beyond these classes, we have other standard library classes in the collections mode that we can use:

  • deque

  • ChainMap

  • OrderedDict

  • defaultdict

  • Counter

We have three standard design strategies, too. We can wrap any of these existing classes, or we can extend a class.

Finally, we can also invent an entirely new kind of collection. This requires defining a number of method names and special methods.

Design considerations and Trade-offs

When working with containers and collections, we have a multistep design strategy:

  1. Consider the built-in versions of sequence, mapping, and set.

  2. Consider the library extensions in the collection module as well as extras such as heapq, bisect, and array.

  3. Consider a composition...