Last Updated:

Custom Objects for Composition Relations

Andy Lapping Helper

Overview

Today I got asked an interesting question:

How can I have two drawing tools that create compositions of different objects of the same class? 

The answer wasn't quite as straightforward as I thought!

Rhapsody has a property PartMetaclassName which you can specify on a new term stereotype based on classes. If you have a new term stereotype based on objects and you specify that stereotype as the name in the PartMetaclassName property then, when any instances of that class are created, they become those custom objects instead of (for example) parts. 

The problem is that Rhapsody only considers that property on a class, not on any new term stereotype based on a composition. So essentially for each class you can only specify one custom object.

The Solution

The solution is to provide a small helper, triggered by the application of the composition new term stereotype (so its very efficient with no impact on modeling - the helper would only ever be called when a new composition is drawn).

That helper checks the PartMetaclassName property which Rhapsody ignores (this saves inventing a new property and provides behavior which Rhapsody should have done).

To make things robust and performant - that property should use the full path name of the object stereotype, not just the name. That way the Java helper can look directly for the stereotyope instead of trying to search for it by name. If the stereotype exists, the helper applies it.

Here is a sample model and the sample eclipse project that listens for the application of the stereotype: Sample