How to define an interface in a Component Diagram?

0 votes
asked May 20, 2020 in Question / help by solarjoe (160 points)

How can I definen aninterface in a Component Diagram?

The documentation at https://plantuml.com/en/component-diagram as interface blocks defined using

interface "Last\ninterface" as Interf4

But how to add fields?

I tried to use the syntax from the class diagram

interface "Last\ninterface" as Interf4{
  String data
  void methods()
}

and this works when I use the "Edit online" on the page, but not in my IDE (VS Code with jebbs PlantUML).

Is this the correct syntax?

1 Answer

0 votes
answered Nov 1, 2020 by The-Lu (74,900 points)
edited Nov 1, 2020 by The-Lu

Hello S.,

1/ mix class interface and component

In order to mix class interface and component or deployment element, you must use the 'allow_mixing' keyword, then we observe the expected result:

@startuml
allow_mixing

interface "Last\ninterface" as Interf4 {
  String data
  void methods()
}

component C
database D

C -> Interf4
Interf4 -> D
@enduml


[See on PlantUML online server]

2/ mix component interface and component

In order to mix interface and component or deployment element, you must use the long description with '[', ']', or long string, then we observe the expected result:

@startuml
interface Interf4 [
Last interface
String data
void methods()
]

component C
database D

C -> Interf4
Interf4 -> D
@enduml


If that can help,
Regards,
Th.

...