Bag
Class Diagram

Bag
Class Specification
Invariant
A Bag<ItemType> object...
- is a container of zero or more other objects
- is capable of storing anything that conforms to the instantiated argument for ItemType (This instantiated argument can be any class name.)
Constructor
Method
public Bag<ItemType> ( )
post: this is an empty container (i.e. size() == 0)
Update
Methods
public void insert ( ItemType z)
post: this == this@pre with z inserted
and size() = size()@pre + 1
public void remove ()
pre: size() > 0
post: this == this@pre with one item removed
and size() = size()@pre - 1
Query
Methods
public int size ()
post: result ==
the number of items in this
Bag
public ItemType item ( )
pre: size() > 0
post: result == one of the items from this Bag