Subclassing OrderedSequence
Andrew P. Black
black at cse.ogi.edu
Sat May 5 05:34:59 UTC 2001
At 18:00 +1200 2001.05.02, Richard A. O'Keefe wrote:
>
>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.
But it could, if you are clever.
We are used to thinking that species when sent to a collection
instance has to return a class. But that is not actually the case.
What happens to the result of "self species"? The code sends it new
or new: size. So, as long as the object that you get back from self
species understands new or new:, everything will be well. We need
only a factory, not a class.
In your case, if you would like some initialized instance variables,
you can build an object in #species that has them. And then when you
send the new: method, you could adjust it's size, or you could make a
copy with a different size.
This is where a type inference system would be really nice. It would
tell us at a glance exactly what all of the existing classes do with
self species. (You would find that you have to implement hash too.
and who knows what else...)
Andrew
More information about the Squeak-dev
mailing list
|