March 19, 2024

Implementing a Queue with Smalltalk

 

Maybe it was the culture of rationing in post-war Britain, but queues, and the act of queuing, seemed to play an integral part of life when I was a child. Gradually this activity has been eroded and replaced with a more Darwinian kind of behaviour. However, on occasion, circumstance demands the requirement for a queue.

The Quad Gallery have, as I have mentioned, a stable of thoroughbred artists. Top of the heap, critically acclaimed, and the jewel in Cordelia Pleydell-Bouverie's tarnished crown, sits Bryan Walker. Year in, year out, Walker has proved to be one of the gallery's top earners.

His pictures have consistently clocked up acreage and sales. A normal Walker show will consist of six paintings, each measuring four metres in height by nine metres in width. Each show is a sell-out. In fact the norm is for the paintings to be sold prior to the opening. However the gallery have a problem with Walker, because he provides them with just six pictures every three years. The gallery have the buyers, they just don't have the product.
"We have to beat them away with sticks darling.", implored Cordelia in a vain attempt to reduce the yardage and increase the productivity. "Why not paint some small pictures?".
Unfortunately for Quad this falls on deaf ears. Bryan makes a nice living by keeping output to a minimum. Consequently the gallery need a queue for buyers of his paintings. How is this implemented?

On the face of it, an OrderedCollection object would seem to be adequate.

bwBuyers := OrderedCollection new.
bwBuyers add: 'Harvey J. Endelstein';
         add: 'Betty and Saul Rifkin';
         add: 'Theodore S. Kanutt III';
         add: 'Cray Devine';
         add: 'Steve Gideon'

1 2 3 4 5
'Harvey J. Endelstein' 'Betty and Saul Rifkin' 'Theodore S. Kanutt III' 'Cray Devine' 'Steve Gideon'

 

Bryan finally condescends to pull out another winner and, at a mere $100,000, Harvey J. Endelstein should soon be receiving "Mojo Blues 66". The queue can be shortened with the following line of code

bwBuyers removeFirst
which answers with 'Harvey J. Endelstein'

So what's the problem? Well in short, Cordelia wants control.

The fact that Harvey J. Endelstein was first in does not give him, in Cordelia's eyes, the right to be first out. In fact the actor Steve Gideon so overwhelmed Cordelia on his last visit to the gallery, that although last in, she has determined that Steve should be first out. The FIFO nature of queues does not always lend itself to Darwinian reality.

There is also another problem with OrderedCollection. Although Cordelia is capricious and manipulative, she is not stupid. Once she has a buyer on her books she is not about to lose him. In the protocol of OrderedCollection is the message selector at:put: which if used for any reason results in a lost buyer.
"Darling, the only way I lose them is when they die."
No, OrderedCollection just doesn't meet the requirements. Cordelia needs more security.

Macroconcepts decide that a new class, BuyerQueue, is required.

Next page » Queue and BuyerQueue

Previous page « The retrospective collection

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Up to top of page