This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.
preface
PlantUML is a language, master to achieve wySIWYG effect, that is to write language way, you can draw the required sequence diagrams, flow charts, use case diagrams, etc. Here, I hope we can learn, do system design at ordinary times can use.
Sequence diagram
A simple example
You can use -> to draw messages passed between participants without explicitly declaring participants. You can also use –> draw a dotted arrow. Alternatively, you can use <- and <–, which do not affect drawing but improve readability. Note: This applies only to sequence diagrams; the rules are different for other diagrams.
@startuml User -> Authentication center: Login operation Authentication center -> Cache: Stores (key=token+ IP,value=token) Token user <- Authentication center: Returns token user after authentication -> Authentication center: Next access header Carries a token Authentication Center <- Cache: key= Token + IP Obtain the token other services <- Authentication center: exists and succeeds in verification. Other services -> User: informati on @endUMLCopy the code
The legend is as follows:
Activation and cancellation of lifelines
@startuml
participant User
User -> A: DoWork
activate A
A -> B: << createRequest >>
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: RequestCreated
deactivate B
A -> User: Done
deactivate A
@enduml
Copy the code
The illustration is as follows:
Declare participant
Declaring a participant using the Participant keyword gives you more control over the participant. The keyword participant is used to change the order of the participants. You can also declare an actor using the following keywords, which will change the appearance of the actor:
- Actor (role)
- We have a boundary.
- I’m in control of it.
- An entity is an entity.
- Database (database)
- Collections
- Queue
@startuml
participant participant as Foo
actor actor as Foo1
boundary boundary as Foo2
control control as Foo3
entity entity as Foo4
database database as Foo5
collections collections as Foo6
queue queue as Foo7
Foo -> Foo1 : To actor
Foo -> Foo2 : To boundary
Foo -> Foo3 : To control
Foo -> Foo4 : To entity
Foo -> Foo5 : To database
Foo -> Foo6 : To collections
Foo -> Foo7 : To queue
@enduml
Copy the code
Use cases
Use cases defined
Use cases are enclosed in parentheses (two parentheses look like ellipses). Use cases can also be defined with the keyword usecase. You can also define an alias with the keyword AS that can be used later when you define the relationship.
@startuml
(First usecase)
(Another usecase) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
Copy the code
The role definitions
The character is wrapped in two colons. You can also use the actor keyword to define roles. You can also use the keyword as to define an alias that can be used later when you define the relationship. In later examples, we will see that the role definition is optional
@startuml
:First Actor:
:Another\nactor: as Man2
actor Woman3
actor :Last actor: as Person1
@enduml
Copy the code
A complete example
@startuml
left to right direction
skinparam packageStyle rectangle
actor customer
actor clerk
rectangle checkout {
customer -- (checkout)
(checkout) .> (payment) : include
(help) .> (checkout) : extends
(checkout) -- clerk
}
@enduml
Copy the code
The class diagram
The element declaration
@startuml
abstract abstract
abstract class "abstract class"
annotation annotation
circle circle
() circle_short_form
class class
diamond diamond
<> diamond_short_form
entity entity
enum enum
interface interface
@enduml
Copy the code
Relationships between classes
Relationships between classes are defined by the following notation:Use.. Instead of — you can get a dot and a line. The following graphs can also be drawn under these rules
@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
@enduml
Copy the code
Activity Diagram (Flow chart)
@startuml
start
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
@enduml
Copy the code
Add methods
To declare a field (object property) or method, you can use the field name or method name that follows it. The system checks for parentheses to determine whether it is a method or a field.
@startuml
Object <|-- ArrayList
Object : equals()
ArrayList : Object[] elementData
ArrayList : size()
@enduml
Copy the code
Here you can recommend plantUML. Flying Book supports plantUML. Welcome to use it.
Welcome attention: programmer wealth free road
Reply: plantUML, learning documents are available
The resources
- plantuml.com/zh/
- Usermanual. Wiki/Pdf/PlantUM…
- Bytedance. Feishu. Cn/docs/doccn5…