Manoj Majumdar
Manoj Majumdar

Reputation: 525

PlantUML script for inheritance

Inheritance hierarchy diagram

Whenever I extend two interfaces from the same interface, in the diagram, it creates separate arrows. I just want a single arrow with branching like this. Is there any script in PlantUML to do this?

Upvotes: 1

Views: 2042

Answers (2)

Peter Prescott
Peter Prescott

Reputation: 908

If you just want two inheriting entities to share an arrow, you can connect the second to the line connecting the first entity to its generalization:

class Entity
class Generalization
class OtherEntity
Generalization <|-- Entity
(Entity, Generalization) -- OtherEntity


Unfortunately if you try this for more it generates more lines so doesn't work. Eg.

class Entity
class Generalization
class OtherEntity
Generalization <|-- Entity
(Entity, Generalization) -- OtherEntity

class AnotherEntity
(Entity, Generalization) -- AnotherEntity

gives this:

which isn't what we want.

Upvotes: 0

Frelling
Frelling

Reputation: 3507

The set of tools - GraphViz - used by PlantUML is primarily for drawing graphs (i.e. nodes and edges); hence the individual realization relationships.

While showing realizations as such is useful at times for depicting interface hierarchies, diagrams can quickly become a "rat's nest" of relationships, potentially obscuring the bigger picture.

You might consider preferring the use of the short-hand "Lollipop" notation to indicate realizations of an interface. For example,

enter image description here

Layout can be a bit tricky at times if you want to show interface details in the same diagram. The script to produce the above is as follows:

@startuml
together {
   interface Widget {
     callFred()
     callBarney()
   }

   class A
   class B
   class C
}

Widget ()- A
Widget ()- B
Widget ()- C
@enduml

Upvotes: 2

Related Questions