Today I experimented a little with the new Slots feature of Pharo 4.0. As
an example I implemented support for associations/relationships.

With it you can link two slots together so an update on one side will also
update the other side of the association/relationship.

I used these Movie and Person classes for testing:

Object subclass: #SlotExampleMovie
slots: {
#name.
#year.
ToOneAssociationSlot named: #director target: #SlotExamplePerson inverse:
#directedMovies.
ToManyAssociationSlot named: #actors target: #SlotExamplePerson inverse:
#actedInMovies }
classVariables: {  }
category: 'SlotAssociations-Tests-Example'
Object subclass: #SlotExamplePerson
slots: {
#name.
ToManyAssociationSlot named: #directedMovies target: #SlotExampleMovie
inverse: #director.
ToManyAssociationSlot named: #actedInMovies target: #SlotExampleMovie
inverse: #actors }
classVariables: {  }
category: 'SlotAssociations-Tests-Example'

With this definition the director of a Movie must be a Persion instance.
When you set the director of a movie this movie is automatically added to
the directedMovies collection of that person. Off course it also works the
other way around.

It took very little code to add these association slots. I think Slots are
a really nice addition to Pharo! If anyone wants to have a look at the code:

MCHttpRepository
location: 'http://smalltalkhub.com/mc/JanVanDeSandt/Stuff/main'
user: ''
password: ''

Jan.

Reply via email to