Syntax error when declaring a class in PlantUML .puml file

381 Views Asked by At

I have this .puml code:

@startuml

class ClassName {
  // Class members (attributes and methods)
}

participant Object1
participant Object2
participant Object3
participant Object4
participant Object5
participant Object6
control Object7

note left of Object6
  This is a note about the Customer class.
end note

title Sequence Diagram with Decision Blocks

@enduml

and I get this error:

enter image description here

anybody know why I can't declare a class there?

1

There are 1 best solutions below

0
Christophe On

Your diagram is a sequence diagram, and not a class diagram. In UML, the lifelines of a sequence diagram correspond to instances of classifiers and not to classes.

Moreover, it's not a commonly accepted UML practice to model the full details of a class with all its internals in a sequence diagram. So plantuml would not know how to render such a mixture. Therefore it is not accepted in the plantuml language, which only allow a limited number of participant types (e.g. Entity-Boundary-Control which are popular non-standard stereotype), see the online reference in section "Declaring participant"

Here how to relate objects to classes, with ObjectZ without specified class, ObjectX as instance of a given class, and an anonymous object of a given class:

participant objectZ
participant "objectX:ClassName"
participant ":ClassName"

enter image description here

The problem with the quotes, is that it is later difficult to use for modelling the messages exchanged, since you alway need to spell the full quote content:

"objectX:ClassName" -> ":ClassName"

So a practical tip is to make full use of alias enabled by plantuml, to use only a shorter object name later on:

participant "objectX:ClassName" as objectX
participant ":ClassName" as ClassName

objectX -> ClassName