[Newbies] Collection subclasses

Bert Freudenberg bert at freudenbergs.de
Thu Apr 3 06:54:58 UTC 2008


On 03.04.2008, at 04:52, Rob Rothwell wrote:
> On Wed, Apr 2, 2008 at 10:48 PM, Randal L. Schwartz <merlyn at stonehenge.com 
> > wrote:
> >>>>> "Rob" == Rob Rothwell <r.j.rothwell at gmail.com> writes:
>
> Rob> Is one not supposed to make subclasses of these classes, and if  
> so, why not?
>
> Generally, your object "has a" collection, but doesn't qualify to be  
> "is a"
> collection.  If you really want to subclass collection classes, you  
> need
> to peer deeply inside the existing classes, and do the right thing.
>
> It's much easier to implement your object, throw a collection  
> inside, then
> implement the parts of the collection protocol that you end up  
> using, starting
> with #do:, by delegating those to your inside collection.
>
> Thanks...I can accept that for now!
>
> So the behavior I am seeing is to be expected, then?  And how would  
> I have known to expect this?  I guess my assumption was that any  
> object could "extend" any other object!

You can, it just means it is not necessarily a good idea to do so.

And also, since Squeak is dynamically typed, you do not need to  
subclass to have your class be a drop-in replacement for some other  
class. Simply implement the methods that the other class uses, and fine.

- Bert -




More information about the Beginners mailing list