[Seaside] Smalltalk design advice - how to implement generic bi-directional pointers?

itsme213 itsme213 at hotmail.com
Fri Dec 21 06:32:56 UTC 2007

I don't think I have grasped the "Smalltalk Way" to deal with this and am 
looking for some design advice ...

I often repeat this kind of code to maintain relations that I have 
implemented as bi-directional pointers (illustrative example only):

Object subclass: #House
   instanceVariableNames: 'rooms'

House>>addRoom: aRoom
    self basicAddRoom: aRoom
    aRoom basicAddHouse: self

House>>basicAddRoom: aRoom
    rooms add: aRoom

House>>removeRoom: aRoom
    self basicRemoveRoom: aRoom
    aRoom basicRemoveHouse: self

House>>basicRemoveRoom: aRoom
    rooms remove: aRoom

Object subclass: #Room
    instanceVariableNames: 'house'

Room>>addHouse: aHouse
    self basicAddHouse: aHouse

Room>>basicAddHouse: aHouse
    house notNil ifTrue: [house basicRemoveRoom: self]
    house := aHouse


How can I make this relation-management code generic, so I can easily add it 
to any class with any named accessors, any number of times? I prefer to 
avoid DNU approaches if possible as this code will be called in several 
inner loops that need to run fairly tight. I thought traits might help but 
now don't think so.

Thanks - Sophie 

More information about the seaside mailing list