gpt4 book ai didi

uml - PlantUml:围绕接口(interface)对类进行排序

转载 作者:行者123 更新时间:2023-12-03 07:52:31 25 4
gpt4 key购买 nike

我正在尝试使用 plantuml 创建 UML 图,这是我的图:

@startuml
'https://plantuml.com/component-diagram


together {
class Rice {

}
class Egg extends IIngredient{

}
class Avocado extends IIngredient{

}
IIngredient <|-- Rice
}

abstract class IIngredient {
@protected
List<String>? allergens;
@protected
String? name;
@protected
int? price;

String? getAllergens()
String? getName()
int? getPrice()
}

class Salmon {

}
class Tuna {

}
IIngredient <|-- Salmon
IIngredient <|-- Tuna

class Sesame extends IIngredient{

}

class Crisp extends IIngredient {

}
@enduml

结果是:

enter image description here

我想要 IIngrient 为中心,其他类围绕它,如下所示:

像这样:

enter image description here

最佳答案

这是我的看法。

  1. 在链接到顶部之前定义您的界面。
  2. 保持简单的用法。使用 implementsextends 意味着继承的垂直对齐。使用 -r-|> 强制继承链接沿 @Christophe 提到的方向 (l, r, u, d)。
  3. 水平布局不如垂直布局智能。在我的回答中,我只使用了一个具有 rl 关系的类,因为多个类会导致链接弯曲。多个ud流动得很好。
  4. 我不确定您为什么一起使用,但您可以通过在链接上将类分组为 ud 来实现它。
  5. 我还重新格式化了您的 IIngredient 类。也许您希望它成为一个界面?在这种情况下,它是interface IIngredient ...,您应该将关系更改为.r.|>以显示虚线(用于实现)。
@startuml

hide empty members

abstract class IIngredient {
' # means protected visibility
' UML syntax name : type for attributes
' no "optional" like "?" in typescript
#allergens:List<String>
#name:String
#price:int
getAllergens():String
getName():String
getPrice():int
}

Egg -d-|> IIngredient
Avocado -d-|> IIngredient
Rice -d-|> IIngredient
Salmon -u-|> IIngredient
Tuna -u-|> IIngredient
Sesame -l-|> IIngredient
Crisp -r-|> IIngredient
@enduml

enter image description here

关于uml - PlantUml:围绕接口(interface)对类进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76825566/

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