4. Collections

So far our bank system only has three customers, John Smith, Liza Jones and Mary Pole. If the bank gets a new customers we have to add an extra data-item that may refer to the account of this customer, and we thus have to change the code. This is not a solution since we have to terminate the bank system; save the information in all objects in the system; change the code; compile and execute again and restore the objects.

In general we, of course, need to be able to handle an arbitrary number of customers without having to change the code. That is, we must be able to represent the file of accounts from the paper-based banking system.

For this purpose, we may use a collection object to represent the account file. A collection is an object that may represent a group of objects called the elements of the collection.

There are different kinds of collections. In this chapter, we introduce three kinds of collections: Set, Array and OrderedList.