3

I found a definition for association in UML as below. An "association" in UML is defined as a kind of relationship between classes,which represents the semantic relationship between two or more classes that involves connections (links) among their instances .

I am not clear what is semantic relationship. Can anyone explain it with example with comparing it with non semantic relationship?

Christophe
  • 68,716
  • 7
  • 72
  • 138
user3397694
  • 111
  • 1
  • 1
  • 8

3 Answers3

3

Associations in plain text

An association is a semantic relationship. The UML clause means that there is a structural relationship between instances of the associated classes independently of any specific implementation. "Semantic" underlines that the relationship is between the instances themselves, and not just "accidentally" for an operation:

Use associations primarily where there are structural relationships among objects. Do not use them to show transient relationships such as parameters or local variables of procedures.
- Booch, Rumbaugh & Jacobson in Unified Modeling Language User Guide, 2nd edition

More arguments

What is "semantic"?

The term "semantic" is borrowed from linguistics and refers to the meanings behind the words. Linguists and map words (e.g. "Car", "Driver") to their meaning (e.g. a real car, a real person), and analyze the relation between words with a view of this mapping:

enter image description here

So, applying this to UML (modelling language) if you'd have the classes Car and Driver, you CAN model the semantic relationship as an association between the two classes.

What is not semantic?

Not all relationships are of semantic nature. You can have dependencies, which can express a technical relationship:

  • a transient relationship during an operation: with a factory pattern for example, a DriverFactory would «create» a Driver instance. Both instances the factory and the driver are related only at the exact moment of the creation operation. But the two instances are completely independent the nanosecond after.
    The same applies if the implementation of an operation needs to create a local instance of another class. Both classes are not associated, since we could imagine another implementation that works without such an instance.
  • a structural dependency: Maybe an operation require some other classes as parameter. Since the parameters themselves are transient, there is no association. But nevertheless, teh class needs to know about the other class.

For the records, I'm grateful to this public domain contributor for the nice car and driver and to 18f for advice on inclusive communication.

Christophe
  • 68,716
  • 7
  • 72
  • 138
2

The subject of Semantics is sense. If one thing has something that is connected by sense to another thing, it is the semantic relationship. That definition is terribly wide. And, applied to UML relationship, incorrect. It is incorrect for two reasons.

First, UML covers not only Class-Instance languages, such as Java or C++, but pure object languages with heredity created by Prototypes as well. And this second variant is not covered by your definition at all.

Second, in UML you can have class A connected to class B through some complex AssociationClass, that is shown by a box with arrows, not arrow only. And it still will be named an association and it IS a semantic relationship, too. But a the semantic relationship goes from A to B through two classes, it is still a semantic relationship, but it is not an association in UML.

If you are trying to be deep in subject, better read the UML documentation: "An Association classifies a set of tuples representing links between typed instances." (UML 2.5, pharagraph 11.5.1). Notice: ANY link between two instances can be shown as an association. Maybe the book you are reading is wholely not so bad, but in the very place that you have cited the author merely tries to use pretty words not understanding their meaning and not even trying to be understandable to readers and to be CORRECT.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • When talking about UML, you shouldn't say that a "link" is an "association" because UML's use of these terms is different (as you said in the same paragraph: "an association classifies links"). – Gerd Wagner Sep 22 '14 at 13:21
  • @gwag 1. Not me. It is said by documentation. 2. It is not so simple. If association is between classes, it classifies the link, yes. But if it is between objects, it IS the link itself. But the text can be improved. Thank you for your note. – Gangnus Sep 22 '14 at 13:37
  • Gangnus: thank you for your answer. Could you give me simple example for non semantic relationship. then I can figure out what is semantic relationship clearly. – user3397694 Sep 23 '14 at 02:50
  • @user3397694 Yes, it is the relationship, that has NO SENSE, imagined by error. The word is absolutely excessive there. Only erroneous relationships can be non-semantic. – Gangnus Sep 23 '14 at 08:44
  • @Gangnus thanks for answer. let say relationship between"me and my brother" is semantic relationship. And relationship "me and people travelling in the same compartment in a train with me" is non semantic relationship..Is my understating correct? – user3397694 Sep 23 '14 at 09:30
  • @user3397694 If you have any relationship, it has some sense. So, i is semantic. The term could mean something significant, if we'll name semantic the relationships that are ONLY semantic. I.e., you have a model, and all relationships that are not directly supported by it, are pure semantic. But again, I can't see any use of it for UML. – Gangnus Sep 23 '14 at 12:10
  • @Gangnus Actually I have seen quite some relations that did not make much sense ;-) – qwerty_so Dec 18 '22 at 18:44
0

A model says something about the things being modeled. This is its semantics. Almost all elements of UML have semantics, defined in the sections titled "semantics". One exception is the comment. Adding a comment to a model doesn't influence its meaning.

Then why does the UML say this explicitely about associations? The reason is, that an association may or may not say something about the structure. If it doesn't, it is purely semantic.

For example it could tell us, that a Car can have at most one Driver. It doesn't necessarily mean that the car has an attribute of type Driver.

If we want to model that the two associated classes own attributes typed by the other end of the association, the notation will show this by small dots on its ends. Many people are not familiar with this notation and interpret associations without a dot in the same way. However, without the dots attributes are owned by the association itself and the structure of the classes is not influenced.

By the way, a class being the type of a parameter of an operation or having a dependency also means a semantic relationship.

Axel Scheithauer
  • 2,758
  • 5
  • 13