29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OrderedCollection class (respectively). Section seven then presents how the<br />

OrderedCollection class c<strong>an</strong> be used to construct Stack <strong><strong>an</strong>d</strong> Queue classes.<br />

10.2 The Collection class hierarchy<br />

A collection is a group of objects (these objects are called the elements of the collection). Collections<br />

are the <strong>Smalltalk</strong> mech<strong>an</strong>ism for building data structures of various sorts; it is therefore import<strong>an</strong>t to<br />

become familiar with the collection hierarchy <strong><strong>an</strong>d</strong> its functionality.<br />

Class Collection is the abstract superclass of all collections in the system. Figure 10.1<br />

summarizes the collection classes in VisualWorks. Some of the classes illustrated are abstract classes on<br />

which others build. In fact the collection class hierarchy is a classic example of the use of abstract<br />

classes <strong><strong>an</strong>d</strong> how they c<strong>an</strong> be used to group together functionality as well as indicate what is expected of<br />

subclasses. Now might be a go od time stop <strong><strong>an</strong>d</strong> examine the collection class itself. Abstract classes in<br />

this hierarchy include:<br />

• Collection. This is the abstract root class for the whole hierarchy.<br />

• SequenceableCollection. This is the abstract class for collections which have a defined<br />

sequence. That is, the subclasses of this class support the notion of having <strong>an</strong> order associated<br />

with the elements.<br />

• ArrayedCollection. This is the abstract class for those classes which have <strong>an</strong> array like<br />

behaviour. That is, subclasses of this class support the notion of <strong>an</strong> externally defined ordering.<br />

Figure 10.1: Part of the collection hierarchy in <strong>Smalltalk</strong><br />

The concrete classes in the collection class c<strong>an</strong> either be ordered or unordered <strong><strong>an</strong>d</strong> may or may not<br />

possess duplicates. Concrete classes which are unordered include:<br />

• Bag. A Bag contains all the objects put in it, in no particular order. Duplicate objects are<br />

permitted.<br />

• Set. Sets contains all the elements put into it, in <strong>an</strong>y order. Duplicates are not kept; adding equal<br />

objects m<strong>an</strong>y times results in only one such object in the Set.<br />

• Dictionary. Class Dictionary is a subclass of Set <strong><strong>an</strong>d</strong> represents a set of associations<br />

between pairs of objects.<br />

Concrete classes which are ordered include:<br />

87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!