December 30, 2024
OrderedCollection
In Learning Works you will find the following class comment for the OrderedCollection.
"Class OrderedCollection represents a collection of elements explicitly ordered by the sequence in which objects are added and removed. Elements are accessible by external keys that are indices. OrderedCollections can act as stacks or queues. A stack is a sequential list for which all additions and deletions are made at one end of the list; a queue is a sequential list for which all additions are made at one end, but all deletions are made from the other end."
Like ArrayedCollection, OrderedCollection is a subclass of SequenceableCollection but unlike arrays, strings and symbols, instances of OrderedCollection can expand and contract. This page looks at its protocol to see how the sequence, or ordering, of the elements in these objects is determined by the messages that are used to add these elements to the collection.
Let us return to the unordered world of Cordelia's Mayfair gallery and consider how an ordered collection could be used.
Her accountant has suggested that it might be a good idea to have a record
of artists who bring in the most revenue to the gallery.
"The top earners" he says.
"I know them off by heart darling. Ingrates to a man!" replies
Cordelia.
The accountant knows that several of her most successful artists are women,
but considers that deference is the order of the day.
At the end of the year a list of names is supplied and entered as follows
topEarners := OrderedCollection
new.
topEarners add: 'Bill Crynge';
add:
'Sian O''Driscoll';
add:
'Bryan Walker';
add:
'Herve Constantine';
add:
'Phillipa Reynolds';
add:
'Terry Cook'
Several points can be made about this collection.
The criteria that constituted entry into this hallowed list was earnings,
that is commission on sales in excess of £50,000. The number of
artists entered will change and so the collection will grow. On occasions,
death, the fickleness of buyers, or a falling out with Cordelia, will
necessitate the eradication of an element. However, it is more than likely
that the first mishap will keep the associated element hanging on like
a limpet.
The order of entry though is important. Bill Crynge
hits the first spot because of his sell out show of that year.
("Crynge's
minimalist sensibilities evoke the remembrance of things past - Time Out")
Cordelia may well contest Bill's position as numero uno on the grounds
that his installation involved the demolition of the gallery interior.
However, her accountant has insisted that Charles Saatchi's purchase of
ten skiploads of breeze block, at a quarter of a million quid, cements
Bill's place as number one in the list of topEarners.
1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|
'Bill Crynge' | 'Sian O''Driscoll' | 'Bryan Walker' | 'Herve Constantine' | 'Phillipa Reynolds' | 'Terry Cook' |
As each string is added, it occupies a "position" at the end of the collection.
The message answer is the argument of the final add:
message selector in the series, in this case 'Terry
Cook'.
The textual representation of this collection object topEarners
is
OrderedCollection ('Bill Crynge' 'Sian O''Driscoll'
'Bryan Walker' 'Herve Constantine' 'Phillipa Reynolds' 'Terry Cook')
We can now look at other messages in the protocol.
Next page » The protocol of OrderedCollection
Previous page « The protocol of Symbol
⇑ Up to top of page