Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UML Class Diagram - Is it bad practice for lines to cross?

Tags:

uml

Is it bad practice for lines between different classes to cross in a UML diagram? Is it a design smell? Does it indicate that your classes are too tangled or independent or anything? Is it always/generally unavoidable? Or am I overthinking this?

Here is my current UML diagram if interested. You will see that I routed a couple lines all the way around to avoid overlapping....

like image 775
user35358 Avatar asked Oct 19 '25 12:10

user35358


2 Answers

Is it bad practice for lines between different classes to cross

Yes, because it can impede understanding of the graph/diagram.

Is it always/generally unavoidable

Not all graphs are planar (see planarity testing), so sometimes it is unavoidable.

But the problem is not as simple as "I will just route the line around". There are many rules and recommendations that constitute a good layout or contribute to good visual aesthetics; to name just a few:

  • lines crossing (you might have seen in some diagrams a small bridge when lines are crossing)
  • number of line bends
  • total line length
  • hierarchy (typically inheritance lines should be drawn upwards)

You can already see that some of the rules are competing; so layouting is always a balancing act. If you are interested in more detail I suggest googling around for "graph aesthetics" or "automatic (graph) layouting".

Unfortunately most research papers I have are behind paywall, so I cannot link to the pdfs, but some of it can be google-able; e.g. UML Diagram Layouting: the State of the Art or Aesthetics of Class Diagrams

like image 146
Peter Uhnak Avatar answered Oct 22 '25 01:10

Peter Uhnak


In my opinion, line crossings may be unavoidable, but often, it happens when I am trying to show too many things with a single diagram. I see this as a "communication" smell rather than as a design smell.

I often found that explicitly writing down the question I am trying to answer helps spot the model elements that are not strictly necessary and that I should omit. Besides, several diagrams may better convey an idea/design than a single saturated one.

In your example, you could maybe break down your diagram following the colored areas you already identified.

like image 27
fchauvel Avatar answered Oct 22 '25 03:10

fchauvel