How to connect note to multiple links between same pair of classes

0 votes
asked Sep 16, 2022 in Question / help by das-g (140 points)

When I have links (e.g. UML associations) between classes, I can connect a single note so several of them like so:

@startuml
Note "foobar" as N1

Foo -- Bar
(Foo, Bar) .. N1

Bar -- Baz
(Bar, Baz) .. N1
@enduml

PlantUML diagram

I'd like to do the same, but for two links that connect the same two classes

@startuml
Foo --- Bar
Foo --- Bar
@enduml

PlantUML diagram

Is this possible, and if so, how?

1 Answer

0 votes
answered Sep 16, 2022 by The-Lu (64,340 points)

Hello D.,

Here is a proposal, as:

@startuml
Note "foobar" as N1
Foo --- Bar
Foo --- Bar
(Foo, Bar) . N1
(Foo, Bar) . N1
@enduml

  • Would it be ok ?

Regards.

commented Sep 16, 2022 by das-g (140 points)

What's the intended semantic? What would syntax be if one had three or more associations (with different multiplicities, roles, association names or in some other way distinct from each other) between these two classes and only wanted to add a note to some of them?

To be more flexible and more explicit / unambigous for such scenarios, I'd suggest a Syntax like

@startuml
Note "foobar" as N1
Foo --- Bar . N1
Foo --- Bar . N1
@enduml

or (for uniquely named associations, so maybe not a good idea?) like

@startuml
Note "foobar" as N1
Foo --- Bar: foobar1
Foo --- Bar: foobar2
foobar1 . N1
foobar2 . N1
@enduml

commented Sep 16, 2022 by das-g (140 points)

Oh, wait, sorry. I thought you were suggesting a new syntax, The-Lu, but it seems you're showing one that's already working, right?

Re my question about semantics: I played around with it a bit and it seems like if you have n such

(Foo, Bar) . N1

lines, the note N1 will apply to the n links between Foo and Bar last defined before those lines.

...