Subclassing OrderedSequence

Andres Valloud sqrmax at prodigy.net
Wed May 2 07:24:41 UTC 2001


Hello.

> Poking around in the collection classes, I find that sometimes
> self copyEmpty is used to make an empty collection, and sometimes
> self species new: 0.

Probably methods like #collect: have something to do with this.

> The basic problem is that if you have a subclass of OrderedCollection
> (or any other SequenceableCollection) that adds instance variables,
> *sometimes* a selection or slicing method will return an empty result
> that has its additional instance variables appropriately set up, and
> sometimes it will return a non-empty result that _doesn't_ have its
> additional instance variables appropriately set up.

SomeCollectionClass class>>new should return an initialized and ready to
use collection.

> The problem is that using
>     self species new: (size)
> to return a copy of part of a sequence doesn't provide information about
> the additional instance variables.

Chances are that the collection being created is then sent some #add:
messages. But I do not have a current Squeak image right here so I can't
tell for sure :(.

> Before doing this, is there any agreed way to decide which selection/
> filtering/slicing methods should return OrderdCollections and which
> should return objects of the new subclass?

The ANSI Smalltalk spec fits your request very well. The idea,
basically, is that for instance #collect: sent to aSortedCollection may
produce elements that are not comparable with the sorted collection's
sortblock. Therefore you return anOrderedCollection.

Andres.





More information about the Squeak-dev mailing list