[GOODIE] BinaryRelation

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Mar 27 22:47:58 UTC 2003


Daniel Vainsencher <danielv at netvision.net.il> wrote:
	At the risk of sounding quite base and showing my complete lack of
	flight and imagination -
	
	What can I do with it? are there example? applications?
	
If you mean, can I show you code using BinaryRelation,
the answer is no, I had to implement it first.  But I'll use it soon.

When you do information modelling with ER diagrams or UML diagrams,
there are binary relations *all* *over* *the* *place*.  Indeed, you
can technically implement any set-up of relational data base
relations by a set-up of binary relations.  Converting such relations
to code is often awkward; typically you end up with an implementation
that can be traversed in one direction but not the other.

Another name for a BinaryRelation is a "directed graph", and directed
graphs are *amazingly* useful as an information modelling technique.

Let's just take one example.  Suppose you are a running a kindergarten.
You might have a set of CareGivers (nasty neologism) and a set of
Children.  Now there is a binary relation between caregivers (feh!)
and children:
    <caregiver> is-authorised-to-collect <child>
We _could_ implement this by having an instance variable
    canCollect {set of child}
in CareGiver.  But then we can't find the caregivers from the children.
And we have to break the logical symmetry by getting the CareGivers to
do all the relation updates.

Or we _could_ implement this by having an instance variable
    canCollectMe {set of caregiver}
in Child.  But then we can't find the children from the caregivers.
And we have to break the logical symmetry by getting the Children to
do all the relation updates.

Or we could do both, and plug a lot of code into both classes so that
both can do all the relation updates.

OR we could set up MayCollect := BinaryRelation new, get it to update
itself, and traverse it in whichever direction we want, without writing
special-purpose code.

I know which seems simplest to me.



More information about the Squeak-dev mailing list