Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!usc!sdd.hp.com!hplabs!hplextra!hplb!gw
From: gw@hplb.hpl.hp.com (Gunther Walther)
Subject: Re: HELP! Style and design question
Sender: news@hplb.hpl.hp.com (Usenet News Administrator)
Message-ID: <DAGuAA.DB6@hplb.hpl.hp.com>
Date: Tue, 20 Jun 1995 09:56:33 GMT
References: <3s4ba6$8kc@harbinger.cc.monash.edu.au>
Nntp-Posting-Host: gwalther.hpl.hp.com
Organization: Hewlett-Packard Laboratories, Bristol, England
X-Newsreader: TIN [version 1.2 PL0.7]
Lines: 53

Russell Penney (ropen1@giaeb.cc.monash.edu.au) wrote:
: Example:

: I want a list of star systems so I have a StarSystem class. I also have a Game
: class to hold the system list and fleet list etc.
: Each system has an id number to identify it uniquely. The Game class has a
: dictionary which has the id number as the key and the StarSystem object as the
: value. So to return a given StarSystem I just do :

:         Game systems at: ID ifAbsent: [ nil ].
: and then test for nil etc.

: But thinking about it could ( or perhaps should ) I put the dictionary in the
: StarSystem class as a class variable and access it by Class methods. ie

:         StarSystem at: ID
: which would return the object or nil.
: This makes sense to me because I can change the underlying storage method to a 
: SortedCollection for example and not have to change code throughout my classes
: BUT is this the right way of doing things. Am I going to transgress the 
: unwritten laws?

Of cause there is a right way and any transgression from it is
a felony ;)

When I read you posting, I wondered whether you want to use
IDs (some kind of number, string, symbol) at all. Your question
was, how to look up things. My question inital reaction is,
could you avoid looking up things at all? Is there anything
stoping you to store instead of the ID (number, string,
symbol) a direct reference to the object?

Another option is to have a class implementing StarSystem ID.
This class would know how to get a real StarSystem from its ID.

Last and not least I wonder whether your system implements some
kind of super nova as a regular event ;) Unless it does so, star
systems tend to outlive the lifetime of software. In this case
you might want to avoid to use everywhere at:ifAbsent: and
encapsulate the lookup and throw an exception if it fails.

I hope some other people comment on this as well,
this was just my 0.02,

gunther

--
------------------------------------------------------------------
Gunther Walther                 | Phone: +44 117 9228518 (direct)
Hewlett-Packard Laboratories,   |    or: +44 117 9799910 x28518  
Filton Road, Stoke Gifford,     | FAX:   +44 117 9228972
Bristol, BS12 6QZ, U.K.         | EMAIL: gw@hplb.hpl.hp.com
NOTE THAT BRISTOL HAS NOW A NEW AREA CODE: 117 9 CHANGE YOUR RECORDS
