[squeak-dev] design issue of someone trying to think like a smalltaker

C. David Shaffer cdshaffer at acm.org
Tue Oct 16 19:48:45 UTC 2012


On 10/16/12 13:53, Joseph J Alotta wrote:
> Greetings,
>
> I have several Accounts and the accounts have Transactions.
>
> My plan was to instantiate a Transaction and to populate it from a file, and then have each of the Transactions
> attach themselves to an Account.
>
> This is a sort of bottom up design.   
>
> The problem is that I have a bunch of Accounts and Transactions running around the system and no tools for working with them.
>
> I can do Accounts allInstances do: [].   But then I also get old instances (from debugging).
>
> Is this a good way of doing things?  Do I need to have some Collection somewhere, so I can go and find each item
> when I need it?  Like a common control mechanism?  And if so, what would it look like?
>
> Do you think I should create a list of accounts and then each Account will have a list of Transactions?  The old top down approach?
>
> Sincerely,
>
> Joe.


I read through the other responses...maybe one of them already answered
your question.  The only thing I could think to add is...

Normally when you're reading Transactions from a file you have some way
of identifying which transactions are associated with with accounts. 
This takes the form of an account id and is either part of the
transaction file's name or it is give in each transaction record in that
file.  One simple thing to is use that account id as a key in a
Dictionary for looking up the associated accounts:


"I assume that somewhere you have a list of accounts...here's some
stand-in code for creating a dictionary from that list"
accounts := Dictionary new.
accounts at: 1 put: (Account new id: 1; owner: 'Fred Smith'; yourself).
accounts at: 2 put: (Account new id: 2; owner: 'Sally Jones'; yourself).

"Now we read the transaction, I'll assume each transaction knows its
#accountId"
rs := ....read stream on your file...
[rs atEnd] whileFalse:
    [|t|
    t := Transaction readFromStream: rs.
    (accounts at: t accountId) addTransaction t].

Hope that helps.

David




More information about the Squeak-dev mailing list