Plantuml class diagram with multiple children: Any way to bifurcate the arrow?
Asked Answered
H

3

8

My attempt:

Animal <|-- Cat
Animal <|-- Dog

Result:

  ┌────────┐
  │ Animal │
  └────────┘
   Δ      Δ
   │      │
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘

That is not how a class diagram is supposed to look like.

This is:

  ┌────────┐
  │ Animal │
  └────────┘
      Δ
   ┌──┴───┐
┌──┴──┐┌──┴──┐
│ Cat ││ Dog │
└─────┘└─────┘

As suggested, I asked if this is possible on the PlantUML forum.

Hospitium answered 6/9, 2018 at 11:38 Comment(3)
I think the class diagram should / can look like this as the cat and dog are independently derived from animal. From where do you get that the arrows should be joined first?Chemosh
@Chemosh That's how I learnt it. The first illustration in the wikipedia article is also like that.Hospitium
I don't think it is possible in plantuml, maybe best to ask at forum.plantuml.net/questions as well.Chemosh
S
5

You can do something like this:

@startuml
class Animal
together {
  class Dog
  class Cat
}
Animal <|-- Cat
Dog -- (Animal, Cat)
@enduml

result

Secundine answered 21/11, 2018 at 21:45 Comment(1)
Depending on the style the black dot looks bad but I can't find any skinparam nor CSS style to change the color or existence of that dot. Also, it seems that together can't be used inside namespaces but works fine with packages.Arrack
S
6

There's skinparam groupInheritance 2 which will serve your purpose, although it doesn't work with skinparam linetype ortho as one might expect. Alas, GraphViz is the rendering engine, so that has limitations.

@startuml
skinparam style strictuml
hide empty members
skinparam groupInheritance 2
class Animal
class Cat extends Animal
class Dog extends Animal
@enduml

enter image description here

Stroy answered 23/7, 2020 at 21:14 Comment(0)
S
5

You can do something like this:

@startuml
class Animal
together {
  class Dog
  class Cat
}
Animal <|-- Cat
Dog -- (Animal, Cat)
@enduml

result

Secundine answered 21/11, 2018 at 21:45 Comment(1)
Depending on the style the black dot looks bad but I can't find any skinparam nor CSS style to change the color or existence of that dot. Also, it seems that together can't be used inside namespaces but works fine with packages.Arrack
L
2

An interesting thing to do in plantUML but "this is not how class diagram is supposed to look like" is not correct (to my knowledge, at least).

The notation is clear for inheritance/generalization but whether you join the lines before the arrow or have separate lines with separate arrows is a matter of visual preference/making it easier to understand:

Linebreeding answered 28/11, 2018 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.