|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
A container is an object that contains within it other objects. Many of the data structures presented in this book can be viewed as containers. For this reason, we develop a common abstract base class that is extended by the various data structure classes.
The Container base class is defined
in Program
to Program
.
The Container class defines the concrete methods
__init__,
getCount,
getIsEmpty,
getIsFull,
accept and
the abstract methods
purge and
__iter__
and the properties
count,
isFull and
isEmpty.
Conspicuous by their absence are methods for putting objects into a container and for taking them out again. These methods have been omitted from the Container class, because the precise nature of these methods depends on the type of container implemented.