Subclassing OrderedSequence
Richard A. O'Keefe
ok at atlas.otago.ac.nz
Wed May 2 06:00:23 UTC 2001
I have a subclass of OrderedCollection, which adds some instance variables.
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.
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
simetimes it will return a non-empty result that _doesn't_ have its
additional isntance variables appropriately set up.
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.
I was wondering about a refactoring where there would be a new method
copySansContentsForSize: size
"Subclasses of existing sequenceable collections that add
instance variables should override this to set up those
variables in the new object."
^self species new: size
and having the methods that now call
self species new: newSize
call
self copySansContentsForSize: newSize
instead.
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?
More information about the Squeak-dev
mailing list
|