Add qualified associations to class diagrams

+2 votes
asked Aug 22, 2022 in Wanted features by jolund (140 points)

I believe this request may be a duplicate, but I thought I would try asking again since it has been so many years.

I am working on a translator between VDM++ models and PlantUML, and type mappings is integral to VDM (shown in UML as qualified associations). It would be nice if we could get proper representation for these in PlantUML class diagrams, instead of simply putting them in square brackets which makes them blend in with variables and cardinalities and often overlap with other elements.

In the image below is shown what a conventional qualified association looks like (qualifier in smaller box adjoining a class, association going from qualifier to other class).

uml - What is the difference between a qualified association and an association  class and how to choose between them? - Software Engineering Stack Exchange

commented Sep 30, 2022 by Todd Musheno (2,680 points)
@startuml
class top
class bottom

top [Qualifier2] -- [Qualifier2] bottom
top [Qualifier3] -- [Qualifier3] bottom
top [Qualifier4] -- [Qualifier4] bottom
@enduml

Seems broken

1 Answer

+1 vote
answered Aug 22, 2022 by plantuml (295,760 points)

Thanks for the suggestion. We could give a try on this.

However, our main concern is that we are going close to what we can do with GraphViz.
So it might work fine on very simple diagrams but cause many issues on large ones.

First, about the syntax we propose to have:

@startuml
class class1
class class2

class1 [Qualifier] -- class2
@enduml

This way, you could mix qualifier and quantifier:

@startuml
class class1
class class2

class1 [Qualifier] "1" -- class2
@enduml

Now the bad news:

If you are about to have too many qualifiers, like in:

@startuml
class class1
class class2

class1 [Qualifier a] -- class2
class1 [Qualifier b] -- class2
class1 [Qualifier c] -- class2
class1 [Qualifier d] -- class2
@enduml

The drawing will be bad.

Same thing for:

@startuml
class class1
class class2

class1 [This qualifier is very long and will give a very bad drawing] -- class2
@enduml


Since you generate your diagrams from VDM models, I'm pretty sure the diagrams are going to be large.
It would be very useful if you could post here or send us by email an example of generated PlantUML diagrams so that we tell you if we could go for it.

Thanks!

commented Aug 23, 2022 by jolund (140 points)
Thank you for the reply!
Here are two examples of UML diagrams using qualifiers.

https://media.discordapp.net/attachments/924185380293599262/1011352535291932683/unknown.png
https://media.discordapp.net/attachments/924185380293599262/1011352578929479700/unknown.png

I wouldn't want for the qualifiers to take up so much space that there isn't any left for normal associations, so I think it would be nice if the associating class increased in size so as to always leave enough space for other associations. The length of the name of the qualifier can be left up to the user, and I can then truncate it on my side if it's too long (or you could possibly make it an option to truncate?).

For my purpose, there isn't really a need for a quantifier on the qualifier end, but I'm sure others may find it useful.

Large diagrams are likely to be messy either way when generated without specified directions (left, right, up, down) on the associations, so it is already to an extent left to the user of the plugin to tidy up the translated model. I do not mind it being slightly messy.

Hope this helps!
commented Aug 23, 2022 by jolund (140 points)

Here is a diagram of a VDM++ example model in PlantUML using one qualified association. 

image

A main purpose of the translator will also be for teaching, which will rarely require many qualified associations.

Also, which email do you prefer we write to? My colleague and I have a couple more questions regarding our plugin.

commented Aug 26, 2022 by plantuml (295,760 points)

We have implemented a first try.

You can either use last snapshot or use the online server.

@startuml
class top
class class2
class class3
class class4

top [Qualifier2] -- [Qualifier2] class2
top [Qualifier3] -- [Qualifier3] class3
top [Qualifier4] -- [Qualifier4] class4
@enduml

This is really an alpha version, not really tested. The drawing is not perfect. So feedback is welcome.

You can use plantuml@gmail.com or post here.

Thanks!

commented Aug 29, 2022 by jolund (140 points)

Thank you so much, this will definitely work!

If I am to give some feedback (you might even be well aware of these problems):

  • It only works with up to down and left to right directions. If I use down to up or right to left, the qualifier is placed on the wrong end of the associations.
  • The max amount of qualifiers on an empty class (left to right) before it breaks seems to be 3, though I honestly do not mind this restriction at all.
  • I believe qualifiers on the end of the associated class is rarely (possibly never) used, so while I did see some weird behavior, such as this, I don't think it will affect most users.
  • A class with an association to itself with a classifier also looks wonky, though I don't think it makes much sense for qualified associations anyway.
  • In the left to right direction, it seems that the distance to the right class is determined by the first qualifier rather than the longest of all, so you can have qualifiers overlapping a class if the first qualifier is shorter than the rest.
  • It would be nice to have some skinning options (such as color and font size), and if it follows the class skin parameters by default.

Honestly, this will work for my use, thank you very much!

commented Oct 1, 2022 by TT (160 points)

Thanks for the useful feature. I have a little feedback.

case1:

@startuml
class class1
class class2

class1 [Qualifier] o-- class2
@enduml

 

case2:

@startuml
class class1
class class2

class1 [Qualifier] *-- class2
@enduml

 

...