2

I have a piece of statement that I don't understand how to model it in a class diagram. It is about Formula 1 races. The piece is the following:

We can only have one race per circuit in each season

So there is a relationship between CIRCUIT, SEASON and RACE.


I believe that it is a ternary association, but a mate told me that it could be an association between CIRCUIT - SEASON and then an association between that association and RACE:

Association of an association diagram

Is that picture wrong? I mean, association should be between 2 classes as far as I know. Not between a class and an association...

Thank's you very much!!!!

EDIT: The statement was wrong, I restated it and could be translated in: (imagine we have 3 circuits)

  • Circuit A in Season 1 --> Race 1
  • Circuit B in Season 1 --> Race 2
  • Circuit C in Season 1 --> Race 3
  • Circuit A in Season 1 --> Race 4 (This should not be allowed, we can only have one race per circuit in each season)
  • Circuit A in Season 2 --> Race 5 (This is correct)

We can only have 1 race per circuit in each season

asehu
  • 127
  • 10
  • That leaves me even more puzzled. Is your 4th bullet stating that your model is incorrect or vice versa?? – qwerty_so Jan 16 '17 at 18:24
  • Oh, I'm sorry, I meant that it should not be allowed "Circuit A in Season 1 --> Race 4" should not be allowed because we are repeating the Circuit A in the Season 1 (Race 1 and 4 would have the same season(1) and circuit(A) and that should not be allowed). – asehu Jan 19 '17 at 21:43
  • Ok. So my answer is what you are looking for. Only one (or no) race per season and circuit. – qwerty_so Jan 19 '17 at 22:15
  • Yes! Almost, because it would not accomplish the last bullet, right? With your diagram I think that you can only have **Circuit A** in **Season 1** for example (1st bullet) but you would not be able to have **Circuit A** in **Season 2** (5th bullet), because in that diagram each Circuit can only be related with one Season due to the cardinality. – asehu Jan 21 '17 at 07:39
  • Of course you can. **Season 1** and **2** are different. Thus you have a new association to **Circuit A**. The multiplicity relates to the number of instances. – qwerty_so Jan 21 '17 at 08:34

2 Answers2

3

To make Race an association class as desired, make the horizontal connector dashed and remove the multiplicities. The above currently shows sort of a ternary connector (see discussion).

enter image description here

This is equivalent to

enter image description here

The multiplicity 0..1 tells that there is one or no race per season and circuit.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 1
    The OP diagram is not a ternary association. That would have a diamond in the middle with multiplicities only on the class ends. – Jim L. Jan 12 '17 at 21:46
  • @JimL. Usually you'd have the lozenge. Though I read that a Connector can have 2..* ConnectorEnds. I did not search for further details, but would have guessed that above notation would be ternary (though admittedly I've never seen it this way). – qwerty_so Jan 12 '17 at 22:23
  • Connectors are not relevant here. They are for composite structures, like when you want to tell someone how to assemble something specific, when a class diagram allows many variations. There are no nested boxes here, nor are there any _name_ : _Type_ labels on any rectangles. Connectors are similar to links, in that they can be typed by associations. – Jim L. Jan 12 '17 at 22:28
  • @Thomas Kilian, Thank's!! I knew the "association class" connector existed, though I think it would not accomplish the statement: "In each circuit and each season there can be only one race." I think the statement translates in "_you can only have in each season a race in each of the circuits_" so you cannot repeat **circuit A** in the **season 1** for example. – asehu Jan 13 '17 at 07:48
  • I missed that part of the question. Just replace _0..*_ with _0..1_ which will limit it to 1 race per season and circuit. – qwerty_so Jan 13 '17 at 11:14
  • I feel that it is more complex, though I cannot get any better solution. The problem with the 0..1 cardinality is that _"1 season can only be related with 1 circuit"_, right? The fact is that you should be able to have in 1 season multiple circuits, but only one race in each circuit per season. I really appreciate your help, I cannot guess any better solution! I don't know if it is not posible to model that statement in a class diagram. – asehu Jan 15 '17 at 15:38
  • Could you please restate your question accordingly. – qwerty_so Jan 15 '17 at 15:53
  • Apologies for the mistake, you were right about that statement. I took it from an exam and it was clearly mistaken. I restated it. – asehu Jan 16 '17 at 17:13
  • @ThomasKilian: I think that a) the 2 diagrams are not equivalent and b) neither one describes the situation correctly: According to the first diagram each circuit can have at most 1 season, which is not the intended meaning. According to the second diagram each season may have at most 1 race, which is also not the intended meaning, I guess. – Valentin Huber Mar 08 '17 at 09:26
  • @ValentinHuber a) They ARE substitutes. b) Exact definition is always the result of lots of discussions with domain specialists and can not be resolved in a single question/answer here. – qwerty_so Mar 08 '17 at 11:15
0

According to my understanding the following diagram models the situation as desired:

UML diagram

Each season may have Race associations with * circuits and vice versa. If a specific season has a Race association with a specific circuit, then the association has exactly one Race association class instance.

A season doesn't have to be associated with a circution, then there's no race for this combination.

Where does the restriction of having at most one race for each season - circuit combination now come from? This is due to the fact that having a * (or any number > 1) on one association end means that an instance may be associated with more than 1 different other instances, but not several times with one and the same other instance.

In this example, a season instance may be associated with several different circuits, but not several times with one and the same circuit. (If you'd like to model this, you'd have to use e.g. multiple associations or a qualified association)