Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

plantuml

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.

like image 292
user2394284 Avatar asked Sep 06 '18 11:09

user2394284


3 Answers

You can do something like this:

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

result

like image 157
Petr Prouza Avatar answered Oct 11 '22 14:10

Petr Prouza


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

like image 39
Fuhrmanator Avatar answered Oct 11 '22 14:10

Fuhrmanator


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:

  • Try to sketch the image on top of that wiki you linked with distinct arrow from each child to it's parent, it will be much more messy
  • Scroll down a bit on wiki to https://en.wikipedia.org/wiki/Class_diagram#Generalization/Inheritance enter image description here
like image 45
user10715939 Avatar answered Oct 11 '22 14:10

user10715939