Relationships for Squeak

A framework that implements relationships as first class members of the language and extends the browser to support them.

You define relationships between classes and the framework automagically creates responding methods for you to use. This is not only faster than implementing these methods yourself, it's also a lot easier to read and edit. Additionally, the generated methods maintain the relationship in a consistent state to prevent common bugs.

The browser extension helps in creating new relationships by providing good templates. Usually, you only select the first class, the relationship-type and write the name of the other class. Compare this to Ruby On Rails where you have to open the first class, type the relationship-type and write the name of the other class - and then do the same thing again in the other class (for bidirectional relationships)!

How to Install


When checking out from Monticello, an additional instance variable is added to Class, causing a lenghty recompile. You probably want to do this on a new image.

To open the browser that supports relationships, you need to do: RelationshipBrowser open

How to Use

When editing relationships, use the relationship browser: RelationshipBrowser open

I'll use a simple example to illustrate the use of this framework: We have a class Artist and a class Artwork. Artists can create many artworks, but an artwork can only have a single artist. We therefore have a one to many relationship between artist and artwork.

Create a relationship

In the relationship browser, select the Artist class and click on the relationship symbol: -->

In the category menu, select OneToMany. As you can see, there is a template for a OneToManyRelationship in the edit pane. Simply add the Artwork class as the right class and save. The new relationship has been created.

If you go back to the instance view, you can see that Artist does now have the methods addArtwork:, artworks and removeArtwork. Artwork has the method artist.

Edit a relationship

Assume we have found out that sometimes, multiple artists collaborate to create an artwork.

Go back to the relationship view (use -->) and select the existing relationship. The edit pane is filled with the previous values. To create a many to many relationship, replace OneToManyRelationship with ManyToManyRelationship. Hit save and look at the newly generated methods.

Assume all artworks in this relationships are paintings. We don't want to create a new subclass for this, but change the name used in the methods.

Select the existing relationship and add a name for the right class: rightClassName: 'painting' and save. The methods will be renamed.

Known limitations

The relationships are not added to monticello when saved (however, the generated methods and instance variables are - your code still works).

Generated methods are editable. Don't do it!

Generated instance variables are editable and accessible. Don't do it, use the accessors instead!

How to Extend

RelationshipDescription is an abstract class which encapsulates a lot of the shared logic. The inheriting classes implement the generation / removal of the instance variables and methods needed for its specific type.

RelationshipBrowser implements the changes for relationships on top of the standard browser from Squeak. It mostly overrides existing methods and uses the relationships like one would from the workspace.


To date the following contributors:

  • Christoph Neijenhuis
Last modified 11 years ago Last modified on 03/07/2011 09:43:15 PM

Attachments (2)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.