Sparx Systems Forum
Enterprise Architect => Uml Process => Topic started by: NigelSimpson on November 30, 2004, 08:48:00 am
-
How can I represent mutually exclusive associations in a UML diagram? I used to do this in Entity Modelling with exclusive arcs on the relationships. I want to be able to say that Class A is associated with Class B OR C (but never both).
In simple cases, I can deal with it by subtyping (Class A.1 is associated with Class B, Class A.2 is associated with Class C). However, where there are already subtypes for a different purpose, and I want to indicate that they all can have this exclusive relationship then I find it impossible without getting in to a chaos of sub-subtypes.
In Select Enterprise there was the notion of parallel inheritance where a class could have two or more strands of inheritance but this is still not as elegant as the entity exclusive arcs. How can this be addressed in Enterprise Architect?
-
Attach a constraint? You can find this by right-clicking the association.
-
Nigel,
UML has no notion of 'a set of mutually exclusive static relationships'. In addition to Thomas' suggestion, you may be also to use OCL to denote this sort of thing. You may already know about OCL, but if not, just google "Object Constraint Language" and you'll get lots of info.
Hmmm, in writing this post, I can't remember ever having to do this in my previous OO projects. I wonder if the OO-style analysis and UML notation allows you to avoid this sort of construct???
Anyways, OCL may be the way to go, so you'll have to include the related 'OCL document' along with your class model to make a complete Requirements Analysis deliverable.
gary
-
In fact, there is a way to unambiguously show this in EA - by using a constraint on the connections.
Suppose a model of ObjectA, ObjectB and ObjectC and two associations ObjectA-ObjectB and ObjectA-ObjectC.
Right click on one of the associations and select "Attach Note or Constraint" from the menu.
At the top of the dialog box, select the Constraint radio button.
In the list of links select both objects and click OK.
You may now enter a constraint that applies to both links.
;)
Bruce
-
Sargasso,
Wow, I never knew you could do that!! Thanks, I think your solution is the way better than mine, and I'll start using this notation..
cheers,
gary
-
Thanks to Gary and Thomas for your suggestions, and thanks to Sargasso who gave me just what I wanted - a simple way to show the exclusivity on a diagram and have all links share the constraint without having to replicate it for each association. Great idea!
-
A lot of nice suggestions.
One question: would it make sense that B and C have a common base class? Or a common interface?
angel'o'sphere
-
The UML 2 specifications also include (in addition to applying constraints to more than one element) the notion of GeneralizationSets and Powertypes.
It would be great if EA supported both of these also.
Paolo
-
Constrained associations can get cumbersome if the number of choices is large. I have seen this sort of construct expressed with a parameterized class, the parameter being a base class for the "one of" set of classes.