Storing

Ned Konz ned at bike-nomad.com
Sat Dec 1 21:06:49 UTC 2001


On Saturday 01 December 2001 12:40 pm, James Stark wrote:
> I thought I would just ask this smalltalk list a couple of questions - I am
> new to smalltalk and this list has been highly recommended in solving most
> smalltalk problems - guess its because all of you are smalltalk gods or
> something... anyways... here it goes.
>
> I have a record subclass declared as follows:
>
> Object subclass: #RECORD - I have various methods for this.
>
> I want to make an array of records - so its one array that stores of type
> records - which I have defined
>
> I have tried the following:
>
> OrderedCollection subclass: #People
>
> - dont know what methods I need - do I have to have an initial 'instance
> creation'!

If you just want a group of people, why bother inheriting from 
OrderedCollection? Just use one as an instance variable in your new class.

Generally, unless you need to change the collection behavior itself, you 
don't want to subclass the collections. Another good reason: you may want to 
keep other data about your collection of people (like for instance, what the 
sorting criteria is, what the name of the collection is, etc.). This is 
easier to do when you can just add another instance variable for them.

> This does compile but it complains at the following:
>
> Smalltalk at: #arecord put: (People new) !

When you subclassed OrderedCollection you made a global for the class People.

If you want to keep an object as a global, give it an upper case name. Or, 
better, make a class variable (or class instance variable) in People to hold 
these collections.

-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com




More information about the Squeak-dev mailing list