Skip to end of metadata
Go to start of metadata

Relationship Manager is a design pattern I wrote a few years ago that I have used in many projects. I have ported it to Boo. See for a web page dedicated to this port and the original The Relationship Manager Design Pattern paper.

Andy Bulka


Relationship manager is a central mediating class which records all the one-to-one, one-to-many and many-to-many relationships between a group of selected classes. It provides a query method. The bottom line: you should implement all relationship code functionality by calling methods on the central Relationship Manager. So if you have, for example, a Person class and an Order class - instead of implementing methods on the Person class e.g. AddOrder(o) and GetOrders() in terms of ArrayLists and whatever, you instead implement those methods by making simple single line calls to a central mediating relationship manager class. Saves a lot of work, especially when you get back pointers on the other side of the relationships that you have to maintain etc.

What is Relationship Manager good for?

> I'd appreciate an 'how to use' example
> to get a quick / better idea on what
> it's useful for when programming

The basic idea with relationship manager is that it is like a
dictionary, which maps relationships between two things, be they object
references or strings or whatever. In my examples I usually use
strings, though object references are commonly used too, in order to
map relationships between object instances.

The benefit over a dictionary is that you can have multiple mappings

then you can ask what 'a' points to and get the result

you can also ask what is pointing to 3, and get the result

One common use of this technology is to do all your wiring between
objects using a relationship manager, thereby saving yourself having to
implement your own one to many lists and having to maintain fiddly
backpointer logic etc. So you still have e.g. an AddOrder(o) method on
your e.g. 'Person' class...its just that you implement the method using
a one line call to the relationship manager - simple! e.g.

There is a bit more of a tutorial code sample in the post


The port from python was slow but sure - certainly not an instant conversion, but many things converted without change, especially the core code of my many many unit tests. Some tips I gathered during the conversion can be found at

API and documentation

Relationship Manager API


Function Name



addRelationship(f, t, id)



removeRelationship(f, t, id)



findObjectsPointedToByMe(f, id)



findObjectsPointingToMe(t, id)



EnforceRelationship(id, cardinality, bidirectionality)

ER(id, c, bi)


findObjectPointedToByMe(fromMe, id, cast)



findObjectPointingToMe(toMe, id cast)



removeAllRelationshipsInvolving(o, id)


Enforcing relationships e.g.

registers the relationship as being one to many and directional, so that e.g. when you add a second relationship between the same two objects the first relationship is automatically removed - ensuring the relationship is always one to one. Alternatively, you could raise and exception.
The findObject methods only find one object (even though many more may be there), and cast it to the appropriate type. This is a commonly used convenience method.

Supporting implementation code

The private guts of the relationship manager now follows. Note you don't need to use the methods of this class, in fact you don't even need to know about this class - just use the above API instead. (Though you can use this class directly if you wish to, its a bit more low level but quite usable):

def GetRelations():
def SetRelations(listofrelationshiptuples):
def AddRelationship(From, To):
def AddRelationship(From, To, RelId):
def RemoveRelationships(From, To, RelId):
def FindRelIdsBetween(From, To) as IList:
def DoesRelIdExistBetween(From, To) as bool:
def DoesRelIdExistBetween(From, To, RelId) as bool:
def FindObjects(From, To) as IList:
def FindObjects(From, To, RelId) as IList:
def Clear():
def FindObject(From, To):
def FindObject(From, To, RelId) as object:

Andy Bulka

  • No labels

1 Comment

  1. I propose not to wait until you get enough cash to buy all you need! You should take the credit loans or just consolidation loans and feel free