gpt4 book ai didi

Plantuml 两个类之间的几个箭头

转载 作者:行者123 更新时间:2023-12-05 05:43:31 28 4
gpt4 key购买 nike

我正在尝试绘制一个类图,其中两个类之间的多个关系是用重数定义的。

默认情况下,结果很糟糕:

@startuml

class Movie {
genres: String[]
minutes: Integer
movie_id: String
rating: Float
title: String
type: String
votes: Integer
year: Integer
}

class Person {
birthYear: Integer
deathYear: Integer
name: String
person_id: String
}

Person "0..*" -> "1..*" Movie : acted_in
Person "0..*" -> "1..*" Movie : directed
Person "0..*" -> "1..*" Movie : produced
Person "0..*" -> "1..*" Movie : wrote

@enduml

Output of default layout

使用 skinparam nodesep 200 会好一点,但多重性仍然关闭:

Output with nodesep 200

我还尝试了 skinparam linetype ortho,它看起来很有前途,但是一旦我还添加了 hide circlehide methods 就搞砸了>…

Output with linetype ortho, hide circle and hide methods

更何况最终我还想添加一个关联类,这真的毁了它:

Output with association class

这是最终代码:

skinparam nodesep 200
skinparam linetype ortho
hide circle
hide methods

class Movie {
genres: String[]
minutes: Integer
movie_id: String
rating: Float
title: String
type: String
votes: Integer
year: Integer
}

class Person {
birthYear: Integer
deathYear: Integer
name: String
person_id: String
}

Person "0..*" -> "1..*" Movie : acted_in
Person "0..*" -> "1..*" Movie : directed
Person "0..*" -> "1..*" Movie : produced
Person "0..*" -> "1..*" Movie : wrote
(Person,Movie) .. Role

class Role {
name: String
}

@enduml

我的问题是:有没有办法用 PlantUML 正确地绘制它?

最佳答案

我不知道如何直接实现更清晰的箭头布局的目标,但您可以通过使用 Person 作为四个子类(例如 Actor、Director、Producer 和 ScreenplayWriter)的泛化来避免这个问题。这些中的每一个都有单独的箭头,它可能会使您的图表通常也更清晰(当然,后者取决于您的品味和图表的目的)

关于Plantuml 两个类之间的几个箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71811493/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com