UML - 如何将类图与子类垂直对齐

标签 uml class-diagram plantuml

在随附的 UML 图中有 5 个类,我想了解如何在子类保持对齐的情况下使 A、B 和 C 类的顶部垂直对齐。请在下面找到我的 UML 代码和屏幕截图。

非常感谢您的支持! :)

目前的样子:

enter image description here

它应该是什么样子(绘画编辑):

enter image description here

UML - 代码:

@startuml TestClassDiagram
scale 800 width
skinparam SameClassWidth true
skinparam ClassFontSize 15

class classA {
{field}  - attribute1  : int
{field}  - attribute2  : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}

class classB {
{field}  - attribute1 : int
{field}  - attribute2 : int
{method} + method1(void)
{method} + method2(void)
}
class classBchild     {
{method} + method1(void)    
}

class classC {
{field}  - attribute1  : int
{field}  - attribute2  : int
{field}  - attribute3  : int
{field}  - attribute4  : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class classCchild {
{method} + method1(void)   
}

classB <|-- classBchild
classC <|-- classCchild

@enduml

最佳答案

PlantUML 中还没有对齐类的功能(目前)。

如果我们在所有元素之间添加箭头,就可以清楚地看到 PlantUML 试图做什么:

它只是从中间对齐所有图表。

使用它,我们可以创建一个 hack,通过用额外的换行符填充类定义直到它们的大小相同,有点达到你想要的结果:

@startuml
skinparam {
    SameClassWidth true
    ClassFontSize 15
}

class A as "classA" {
    {field}  - attribute1  : int
    {field}  - attribute2  : int


    __
    {method} + method1(void)
    {method} + method2(void)
    {method} + method3(void)
    {method} + method4(void)
    {method} + method5(void)
}

class B as "classB" {
    {field}  - attribute1 : int
    {field}  - attribute2 : int


    __
    {method} + method1(void)
    {method} + method2(void)



}

class Bc as "classBchild"     {
    {method} + method1(void)    
}

class C as "classC" {
    {field}  - attribute1  : int
    {field}  - attribute2  : int
    {field}  - attribute3  : int
    {field}  - attribute4  : int

    {method} + method1(void)
    {method} + method2(void)
    {method} + method3(void)
    {method} + method4(void)
    {method} + method5(void)
}

class Cc as "classCchild" {
    {method} + method1(void)   
}

B <|-- Bc
C <|-- Cc
@enduml

关于UML - 如何将类图与子类垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65211892/

相关文章:

java - java 中的企业架构师脚本 : how to change the way of a connector?

java - 如何阅读XMI?

javascript - 在类图中包含 JavaScript 和 HTML 文件?

uml - UML 方法名前感叹号/问号的含义

uml - StarUML 没有打开我的 .uml 文件

.net - 从现有 .Net 项目自动创建 UML 图的免费工具

UML 状态机 : Class diagram of a state with Transitions, 触发器和事件

plantuml - PlantUML 中的网络图未按预期工作?

uml - 如何纠正 PlantUML 线路径

python - 如何在 pandocfilters 中获取带有 Markdown 的字幕?