Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: Rouven on May 04, 2012, 09:22:03 pm
-
Hi everyone,
I have just stumbled across a problem building a logical model where I am not sure about how to accomplish this in UML class diagrams. Scenario:
- There are three classes A, B, C.
- A has to-1-associations with B and C.
- A must only have either an association with B or with C
How to I represent this third aspect in UML? Do I have to use a constraint (which is poorly visualized on class diagrams from what I can tell)? Is it possible find a graphic representation? By googling I found a class diagram that held a dashed line between the two associations marked as "OR", but I don't think it is supported or even part of UML?!
Can anybody help me out? Thanks in advance,
Regards,
Rouven
-
Hi,
I think you can use constraints to achieve (express) this. The visual representation wiith the 'OR' marker could be represented by an 'external' constraint that is defined separate from the association's 'internal' constraint and linked to both of them.
HTH
Günther
-
Hi Günther,
thanks for the input - the external constraint with links to the association seems to work - looks like a note on the diagram, but sufficiently visible an I could go and modify the appearance...
So yes, I think this helps.
Rouven
-
UML standard would be to use the note-like constraint with XOR
and link that with both associations.
Geert
PS. If the associations happen to be compositions as well then you don't need an explicit XOR constraint as this constraint is built in into the definition of a composition.
-
Hi Gert,
first of all thanks for the reply. I think I'll need another pointer into the UML standard or a direct explanation to fully get what you're saying about the compositions.
Assume I have the following classes:
Now I want to model some sort of specification that allows me to specify a value on different granularity with precedence:
- continent - continent is very generic
- continent - airport is "medium" generic
- airport - airport is highly specific
What all of the above have in common is that for my specification element I have two associations, each of which is either a continent or a country or an airport.
How would you suggest I model that using UMLs built-in support for XOR? Whenever I look to OMG for the composition it always seems to have something to do with existence or lifecycle, which is simply not true here. An airport etc. exists without such a relationship to the specification element. A specification element's existence on the other hand can not really be considered as dependent on the e.g. airport.
In my understanding, the only "XOR" about the composition would then be my lifecycle can only be bound to either this or that object, but that interpretation doesn't help me here.
Am I going in the completely wrong direction?
Thanks,
Rouven
-
Rouven,
I don't really understand your example, but of course you should only use composition if it is appropriate.
In this case there could be compositions between Continent en Country, and between Country and Airport, but I guess that isn't really what you are talking about.
So if composition is not suited you'll have to use the XOR constraint.
Geert
-
I'd agree. Create an association link to both connectors and make it a constraint with the contents {XOR}.
q.
-
Hi,
sorry if the example wasn't clear - lets simplify it and assume I want to build a system that governs language requirements on certain travel routes:
- Europe-to-South America: 1 English
- Europe-to-Brazil: 1 English + 1 Portugese
- Frankfurt-to-Rio de Janeiro: 1 English + 1 Portugese + 1 German
So I define a class like "LanguageRequirement" which then has the aforementioned 3 alternative associations with continent, country, airport in a role "departing from" and 3 alternative associations with continent, country, airport in a role "arriving at".
Maybe this makes things a little clearer. But I think I got your answer and can go forward with that approach.
Thanks!
-
Also I thought using a tree line style for the associations - infers an OR relationship?
-
Also I thought using a tree line style for the associations - infers an OR relationship?
I think what Rouven really meant originally was XOR, as Geert and q. already proposed (just missed that in my proposal).
In general I would expect that a tree line style relationship can be further defined as either AND or OR using the right muliplicities at the connector ends.
WBR
Günther
-
Hi,
sorry if the example wasn't clear - lets simplify it and assume I want to build a system that governs language requirements on certain travel routes:
- Europe-to-South America: 1 English
- Europe-to-Brazil: 1 English + 1 Portugese
- Frankfurt-to-Rio de Janeiro: 1 English + 1 Portugese + 1 German
So I define a class like "LanguageRequirement" which then has the aforementioned 3 alternative associations with continent, country, airport in a role "departing from" and 3 alternative associations with continent, country, airport in a role "arriving at".
Maybe this makes things a little clearer. But I think I got your answer and can go forward with that approach.
Thanks!
A few years ago when I was working in the travveling industry sector I came over exactly the same problem. Yes, it's tricky.
A possible solution could be to introduce a location 'helper' class that composes just 'continent', 'country' and 'airport' for a departure, via and destination. The more specific entries in the composition automatically determine the less specific ones, i.e. country specifies 'continent' and 'airport' specifies both 'continent' and 'country'. This can be modelled using appropriate contraints for the composed attributes. The (usually normalized) DB model relations are not much of help to ensure these semantics.
HTH
Günther
-
Also I thought using a tree line style for the associations - infers an OR relationship?
No. This is only a graphical representation. You should use tree style preferably with generalization where it does not matter which line connects to which client. Wherever you need to attach constraints it is not recommended to use tree style as it becomes almost impossible to distinguish to which connector the constraints are assigned.
q.