在所附的 UML 图中有 5 个类,我想找出类 A、B 和 C 的顶部如何垂直对齐,同时子类保持对齐。请在下面找到我的 UML 代码和屏幕截图。
非常感谢您的支持! :)
目前的样子:
它应该是什么样子(油漆编辑):
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 正在尝试执行的操作:
它只是从中间对齐图中的所有类。
使用这个,我们可以创建一个黑客,通过用额外的换行符填充类定义,直到它们的大小相同,来实现您想要的结果:
@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