Storing
Hannes Hirzel
hirzel at spw.unizh.ch
Sat Dec 1 21:16:43 UTC 2001
On Sat, 1 Dec 2001, 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
.....
A simple possible solution (the actual solution depends on what
you might want to achieve, maybe you give additional details):
Do a subclass 'Person' of Object with methods like name, date of birth,
adress, hobby and so one.
Use a dictionary (correponds to a hash in Perl) to store the persons.
people _ Dictionary new.
p _ Person new.
p firstname: 'James'.
p name: 'Stark'
p hobby: 'Squeak'.
people at: 1234 put: p.
Or if you like to keep the ordering:
people _ OrderedCollection new.
people add: p.
Depending on what you want to do with your person collection you might
need to write a so-called wrapper, an object which wraps either a
dictionary or an ordered collection and shows accessor methods to the
collection only.
Cheers
Hannes Hirzel
More information about the Squeak-dev
mailing list
|