Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: Rouven on May 04, 2012, 09:22:03 pm

Title: 3 classes, 2 associations: either one or the other
Post 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:
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Makulik on May 04, 2012, 10:01:07 pm
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Rouven on May 04, 2012, 10:32:44 pm
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Geert Bellekens on May 07, 2012, 06:19:16 pm
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.
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Rouven on May 07, 2012, 07:48:17 pm
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:
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Geert Bellekens on May 07, 2012, 08:25:18 pm
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: qwerty on May 07, 2012, 09:28:58 pm
I'd agree. Create an association link to both connectors and make it a constraint with the contents {XOR}.

q.
Title: Re: 3 classes, 2 associations: either one or the o
Post by: Rouven on May 07, 2012, 09:38:44 pm
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:

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!
Title: Re: 3 classes, 2 associations: either one or the o
Post by: David Rains (bioform) on May 08, 2012, 03:56:20 am
Also I thought using a tree line style for the associations - infers an OR relationship?
Title: Re: 3 classes, 2 associations: either one or the o
Post by: g.makulik on May 08, 2012, 04:25:16 am
Quote
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: g.makulik on May 08, 2012, 04:41:00 am
Quote
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
Title: Re: 3 classes, 2 associations: either one or the o
Post by: qwerty on May 08, 2012, 06:02:26 am
Quote
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.