5

I am reading "UML distilled" by Martin Fowler, and during reading about association classes I got this quote:

What benefit do you gain with the association class to offset the extra notation you have to

remember? The association class adds an extra constraint, in that there can be only one instance of

the association class between any two participating objects.

Then there was an example, but I want to make sure I got this right, if for example I got:

 ---------            ---------
|         |*        *|         |
| CLASS A |----------| CLASS B |
|         |     |    |         |
 ---------      |     ---------
                |
          ______|______
         |             |
         |             |
         |  CLASS C    |
         |             |
         |_____________|

then, for every distinct pair (instance of A,instance of B) there exists only one instance of class C.

So if I would take A1,A2,B1,B2-instances then for (A1,B1) (A1,B2) (A2,B1) (A2,B2) I would get 4 instances of C, nothing less, nothing more?

Christophe
  • 68,716
  • 7
  • 72
  • 138
Andna
  • 6,539
  • 13
  • 71
  • 120

4 Answers4

2

From the UML 2.5 specification:

Note that when one or more ends of the AssociationClass have isUnique=false, it is possible to have several instances associating the same set of instances of the end Classes.

Mr. Fowler may have gotten the facts wrong. There is no extra constraint, just the ability to store additional property values.

When isUnique=false, extra properties allow one to model multiple visits to the same doctor on different dates, or multiple purchases of the same products on different dates, for example.

Jim L.
  • 6,177
  • 3
  • 21
  • 47
  • On which page do they say that? On p. 239, they say "When one or more ends of the Association have isUnique=false, it is possible to have several links associating the same set of instances." Notice that they didn't have this multi-set semantics of association ends in UML 1.x, to which Martin Fowler's old statement refers. So, he didn't get the facts wrong (please correct your sentence about him), but OMG has modified the semantics. – Gerd Wagner Sep 17 '15 at 16:33
  • Can someone tell me whether Martin Fowler's third edition of UML Distilled makes the same claim about UML 2.x? Note that I did say "may". – Jim L. Sep 17 '15 at 21:35
  • Your answer is confusing, because yo do not explain that, by default (when the association ends are unique), there is this constraint, and only if at least one of the association ends is annotated as non-unique, there is no such constraint. – Gerd Wagner Sep 18 '15 at 19:38
  • The annotation is optional, so one cannot assume the default constraint is in effect when no annotation is present. This may be a flaw in the spec. – Jim L. Sep 19 '15 at 04:43
  • 2
    I don't know where this quote comes from, but in the 2.5 spec I download from http://www.omg.org/spec/UML/2.5/PDF dated march 2015 i find this note in §11.5.3 page 199 -- NOTE. Even when all ends of the AssociationClass have isUnique=true, it is possible to have several instances associating the same set of instances of the end Classes. -- This statement does not leave room for interpretation: the statement in UML distilled is outdated. – Catweazle Sep 26 '15 at 19:50
1

That'd be correct, without any intention to mix concepts here but it's similar to Tables in a database where:

A 1-* C
B 1-* C

Where C can be seen as the result of breaking a many to many relationship between A and B.

For each row on B can only exist 1 and only 1 Row C and That Particular row (on C) can only me related to 1 row on A. Hence, for each Pair of unique rows on A and B can only exist 1 row on C or none, because the * indicates 0 or more.

lmcanavals
  • 2,339
  • 1
  • 24
  • 35
  • I think you have not understood the UML distinction between an "association class" C representing a binary association between A and B and a class C associated with both A and B. – Gerd Wagner Sep 15 '15 at 11:25
  • This answer is incorrect with respect to the number of possible rows. Please see my answer quoting the UML spec. – Jim L. Sep 16 '15 at 04:45
0

Your reasoning is correct: if an association class does not have one or both association ends annotated with {nonunique}, then it implies the constraint that there can be only one link between the same objects (as explained by Martin Fowler).

Notice, however, that the option of non-unique association ends has only been added in UML 2 (in 2005), and Martin Fowler's book (from 2003) refers to UML 1.x.

Some examples may help. For instance, the association LandPurchase between Person and PieceOfLand could be modeld as a UML association class (with default unique association ends), since there can be only one purchase link between a person and a piece of land. The association ProductPurchase between Person and Product can only be modeld as an association class if the association end at the Product side is annotated as {nonunique} since there can be more than one purchase link between the same person and the same product (as a type). For instance, I can buy more than one Tesla Model S cars (if I would have the money).

Similarly, in the case of Appointment between Person and Doctor, since the same person can have more than one appointment with the same doctor, the association end at the Doctor side has to be annotated as {nonunique}.

Gerd Wagner
  • 5,481
  • 1
  • 22
  • 41
  • It is incorrect to say, "the binary association ProductPurchase between Person and Product cannot be modeled as a UML 'association class'." Please see my answer quoting the UML spec. – Jim L. Sep 16 '15 at 20:18
  • Thanks for pointing this out. I've revised my answer. Now it's correct. – Gerd Wagner Sep 18 '15 at 22:23
  • The uniqueness designator is optional in the BNF. Therefore, without an explicit {unique} or {nonunique} marking, one cannot say it implies there can only be one link between the same objects. – Jim L. Sep 19 '15 at 04:37
  • To be more clear, it's not about whether an end is annotated, it's about which way the end's meta property is set. – Jim L. Sep 19 '15 at 04:52
  • In a visual model you do not set meta-properties, but you add annotations. The default value of the `isUnique` meta-property is `true`, Consequently, if an association end in a diagram does not have a `{unique}` annotation, `isUnique` is `true`. – Gerd Wagner Sep 19 '15 at 07:14
  • Is there something in the UML spec that led you to that conclusion? – Jim L. Sep 19 '15 at 10:44
  • Yes. Just look up the abstract syntax of MultiplicityElement. – Gerd Wagner Sep 20 '15 at 19:59
-1

Association in UML represented (have) logical sens (UML is not tool for database modeling!). Association describe possible logical fact. E.g. Two person A and B could be married, we can draw this as association, it is representing meaning like a "we know that exist an logical connection between person A and person B". If we know what that is, we draw class association [marriage cerificate] as materialised fact.

Jarek Zelinski
  • 167
  • 1
  • 3