【发布时间】:2021-01-28 08:24:21
【问题描述】:
在下面的 UML 类图中,我想明确的是 Course.chapters 和 Chapter.sections 成员分别由 AugmentedList<Chapter> 和 AugmentedList<Section> 实现。
我知道在 SO 上应该避免使用图像,所以这里是与此图对应的 Kotlin 代码。
interface AugmentedList<E>: List<E> {
val introduction: String
val conclusion: String
}
interface Section
interface Chapter {
val sections: AugmentedList<Section>
}
interface Course {
val chapters: AugmentedList<Chapter>
}
我知道将模板类绑定到非模板类的方法是通过binding,但是我想避免在图表中添加“具体”接口,因为接口AugmentedList<Chapter> 和AugmentedList<Section>不会在代码中显式实现。
也许存在未实现但仅在 UML 图中使用的接口的构造型?
我还考虑将限定符 chapters: AugmentedList<Chapter> 添加到 Course 接口,但我觉得这不是限定符的目的。
是否有正确的方法来精确说明如何实现组合?
【问题讨论】:
标签: kotlin templates types uml class-diagram