Author Topic: 3 classes, 2 associations: either one or the other  (Read 4782 times)

Rouven

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
3 classes, 2 associations: either one or the other
« 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

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #1 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

Rouven

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #2 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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11815
  • Karma: +457/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: 3 classes, 2 associations: either one or the o
« Reply #3 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.

Rouven

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #4 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:
  • airport
  • country
  • continent
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11815
  • Karma: +457/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: 3 classes, 2 associations: either one or the o
« Reply #5 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

qwerty

  • EA Guru
  • *****
  • Posts: 12778
  • Karma: +363/-295
  • I'm no guru at all
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #6 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.

Rouven

  • EA User
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #7 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:
  • 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!

David Rains (bioform)

  • EA User
  • **
  • Posts: 83
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #8 on: May 08, 2012, 03:56:20 am »
Also I thought using a tree line style for the associations - infers an OR relationship?

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #9 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
« Last Edit: May 08, 2012, 04:26:04 am by g.makulik »
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #10 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
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

qwerty

  • EA Guru
  • *****
  • Posts: 12778
  • Karma: +363/-295
  • I'm no guru at all
    • View Profile
Re: 3 classes, 2 associations: either one or the o
« Reply #11 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.