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

Amos aaamos at gmail.com
Sat Dec 22 09:08:29 UTC 2007


Hi Sophie,

I have to agree with most of the other people who responded -
generelly, try not to do it. Reconsider your design, it should be
possible to avoid it. There's a reason there's no convenient
"here's-one-we-prepared-earlier" way to do it. ;-)

Also, if you absolutely do have to do it, looking for a way to
"streamline it for next time" will only make you lean towards choosing
that method again when you consider your next design, instead of
trying to avoid it like the plague (as you probably should) and
looking for alternative designs.

Having said that, the closest I can come to thinking of a situation
where something like that is needed is in UIs, where a component needs
to be updated when something on the parent canvas changes, and vice
versa. I'm not sure whether that can be translated to what you need it
for, but the way it's generally done there (in VW, that is, haven't
really played around with UIs in Squeak yet) is via dependencies - an
object registers an interest in changes in the other object. Like I
said, I don't know whether that's applicable for your case, but there
you go ;-)

Cheers,

Amos


On 12/21/07, itsme213 <itsme213 at hotmail.com> wrote:
> 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
>
> etc.
>
> 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
>
>
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>


More information about the seaside mailing list