如何在依赖于 属性 的 UML 中对接口实现建模?

How to model an interface implementation in UML that is dependent from a property?

我有一个 class Properties 有两个属性: kind: 亲切 config:配置

Kind 作为枚举类型,其中包含一些字符串。

Config 中包含的内容取决于 kind 的值。

如何在 UML 中建模?

例如,如果我有 "Service" 的 kind 值,则 config 接口将实现为 ServiceConfig。在 ConfigServiceConfig 之间的连接器上添加一个 constraint 注释就足够了吗?

你用约束来建模。这可以附加到 class 或 属性 本身。我不会写 OCL,但那将是最正式的方式。但是,用 { 大括号 } 括起来的纯文本就可以了。另见 https://www.uml-diagrams.org/constraint.html


重新编辑:

Config接口由两个class实现(右下)。约束只是告诉在运行时必须做什么才能实例化 config。当然,它缺少一些细节,比如如果在运行时 kind 会动态改变会发生什么等等