Hi Jan

Excellent! We know exactly whay we want slots and this is exactly for such kind of extensions.

you may want to read the paper of Kasper Osterbye http://itu.dk/people/kasper/cv.htm R.11 Kasper Østerbye. Associations as a Language Construct. In Proceedings of TOOLS 29, Ed. Richard Michel et.al., Nancy, June 7-10 1999. Page 224-235. (pdf)

I would love to have a nice package with such relationships because we used them all the time.
I will blog about your nice experience.

We should probably find a nicer way to declare them.
Stef


Le 21/2/15 21:11, Jan van de Sandt a écrit :
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