|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Python |
A container may be empty or it may contain one or more other objects.
Typically, a container has finite capacity.
As shown in Program
,
a single instance attribute called _count
is used to keep track of the number of objects held in the container.
The _count instance attribute is set initially to zero.
It is the responsibility of the derived class
to update this instance attribute as required.
The purpose of the purge method is to discard all of the contents of a container. This method is declared abstract because the manner in which the purge method is implemented depends on the type of the container. After a container is purged, the value of the _count instance attribute should be zero.
The purpose of the __iter__ method is to return
an iterator that enumerates the objects in the container.
Iterators are discussed in Section
.