I have two class diagrams in PlantUML and would like to define a class in one file and reuse it in the other. See the example below.
diagram1.puml:
@startuml diagram1
class "Foo" as foo {
...attributes
}
@enduml
and diagram2:
@startuml diagram2
!include diagram1!foo
class "Bar" as bar {
...attributes
}
@enduml
Now my expectation is that diagram2 will show me both classes Foo and Bar in the diagram. However, the included class is not shown in the render.
How can this be solved?
The plantuml include statement includes code as if it was typed in that included place (like include files for e.g C / C++ etc. do too). So the code should be like: For Diagram2:
@startuml diagram2
!include diagram1!foo
class "Bar" as bar {
...attributes
}
@enduml
and for diagram1
class "Foo" as foo {
...attributes
}
When you want also show diagram1 as a separate file you have to add an extra file with:
@startuml diagram1_show
!include diagram1!foo
@enduml