长生栈 长生栈
首页
  • 编程语言

    • C语言
    • C++
    • Java
    • Python
  • 数据结构和算法

    • 全排列算法实现
    • 动态规划算法
  • CMake
  • gitlab 安装和配置
  • docker快速搭建wordpress
  • electron+react开发和部署
  • Electron-创建你的应用程序
  • ImgUI编译环境
  • 搭建图集网站
  • 使用PlantUml画时序图
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Living Team

编程技术分享
首页
  • 编程语言

    • C语言
    • C++
    • Java
    • Python
  • 数据结构和算法

    • 全排列算法实现
    • 动态规划算法
  • CMake
  • gitlab 安装和配置
  • docker快速搭建wordpress
  • electron+react开发和部署
  • Electron-创建你的应用程序
  • ImgUI编译环境
  • 搭建图集网站
  • 使用PlantUml画时序图
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Cmake 基本使用
  • Linux和Windows常用命令对比
  • Nginx的使用方法
  • Bash常用语法
  • 使用PlantUml画时序图
  • 使用PlantUML画类图
    • 安装和使用
    • 类的六大关系
    • 案例
    • 注释
    • 参考资料
  • 编译工具链
  • gcc工具的概述和使用
  • 自动化构建工具——Make/Makefile
  • 使用开源AI模型Whisper为视频生成字幕
  • MySQL基础操作
  • 工具
DC Wang
2023-03-12
目录

使用PlantUML画类图

# 使用PlantUML画类图

PlantUML是一个可以让你快速编写UML图的组件。

# 安装和使用

  • vscode中安装PlantUML插件。

    image-20230312074805078

  • 如果想绘制除时序图和活动图以外的图, 就需要安装Graphviz软件。

    Graphviz下载 : graphviz-dot (opens new window)

# 类的六大关系

关系类型 符号 绘图 说明
依赖 <.. image-20230312085035885 use a
关联 <-- image-20230312085016035 has a
继承(泛化) <|-- image-20230312084935042 extern
实现 <|.. image-20230312084904123 implements
组合 *-- image-20230312085108651 二者之间是整体和部分的密切关系,部分的生命周期不能超越整体,或者说不能脱离整体而存在。例如电脑和cpu的关系。
聚合 o-- image-20230312085131067 二者之间是整体和部分的弱关系,整体和部分可以分开,部分的生命周期可以超越整体。例如雁群和大雁的关系、学校和学生之间的关系。

# 案例

@startuml
class person
class student
{
    # String name
    # int age
    - String id
}
class teacher
class course
class computer
class cpu
class harddisk
class water
interface human
{
    +eat()
    +drink()
    +sleep()
    +work()
}

human <|.. person:实现
water <.. human:依赖
person <|-- student:继承
person <|-- teacher:继承
student *-- course:聚合
teacher *-- course:聚合
computer <-- student:关联
cpu o-- computer:组合
harddisk o-- computer:组合

note left of computer:这是一个注释

@enduml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

image-20230312091923968

# 注释

@startuml
class Object << general >>
Object <|--- ArrayList

note top of Object : In java, every class\nextends this one.

note "This is a floating note" as N1
note "This note is connected\nto several objects." as N2
Object .. N2
N2 .. ArrayList

class Foo
note left: On last defined class

@enduml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

image-20230312085450039

# 参考资料

github: plantuml/plantuml: Generate diagrams from textual description (github.com) (opens new window)

官方PDF文档: PlantUML Language Reference Guide (opens new window)

编辑 (opens new window)
上次更新: 2023/03/31, 22:34:04
使用PlantUml画时序图
编译工具链

← 使用PlantUml画时序图 编译工具链→

最近更新
01
ESP32-网络摄像头方案
06-14
02
ESP32-PWM驱动SG90舵机
06-14
03
ESP32-实时操作系统freertos
06-14
更多文章>
Theme by Vdoing | Copyright © 2019-2025 DC Wang All right reserved | 辽公网安备 21021102001125号 | 吉ICP备20001966号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式