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
  • 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.

In the next chapter, we'll closely look at the built-in numbers and how to create new kinds of numbers. As with containers, Python offers a rich variety of built-in numbers. When creating a new kind of number, we'll have to define numerous special methods.

After looking at numbers, we can look at some more sophisticated design techniques. We'll look at how we can create our own decorators and use those to simplify the class definition. We'll also look at using mixin class definitions, which are similar to the ABC definitions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset