The ABCs of Consistent Design

The Python standard library provides abstract base classes for a number of container features. It provides a consistent framework for the built-in container classes, such as list, dict, and set. Additionally, the standard library provides abstract base classes for numbers. We can use these classes to extend the suite of numeric classes available in Python.

In this chapter, we'll look in general at the abstract base classes in the collections.abc module. From there, we can focus on a few use cases that will be the subject of detailed examination in future chapters.

There are three common design strategies for reusing existing classes: wrap, extend, and invent. We'll look at the general concepts behind the various containers and collections that we might want to wrap or extend. Similarly, we'll look at the concepts behind the numbers that we might want to implement.

Our goal is to ensure that our application classes integrate seamlessly with existing Python features. If we create a collection, for example, it's appropriate to have that collection create an iterator by implementing __iter__(). A collection that implements __iter__() will work seamlessly with a for statement.

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

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