gpt4 book ai didi

oop - 具有泛化的类图组合

转载 作者:行者123 更新时间:2023-12-02 18:55:51 25 4
gpt4 key购买 nike

我在这里试图表明 Admin 是 User 的一个子类,通过开放三角关系连接显示。这足以表明子类依赖于主父类存在,还是我需要进一步应用组合?我在下面展示了我的例子。我对此非常困惑。我觉得通过特化箭头显示它就足够了,但我不确定。 enter image description here

最佳答案

Is this enough to show that the sub-class relies on the main parent class to exist or would I then need to further apply composition?

因为一般化 AdminUser,所以如果根本没有 User (User.allInstances( )->size() = 0) 那么也就没有Admin了。当然,您可以拥有 User 而无需 Admin

如果你只是想说除了泛化之外没有什么是必要的。

但是如果你想表明一个 Admin 是一个 User 并且只有 1 个管理员,你可以这样做:

enter image description here

可以看到admin是类User的一个属性(isStatic是true)因为写的是下划线,不需要对所有实例(包括管理员)都有它。

不使用附加关系的另一种表达方式是:

enter image description here

当然,如果您想说至少有一个管理员而不是一个管理员,只需在第一个解决方案中使用多重性 1..* 或修改约束以具有 {allInstances ()->size() >= 1} 在第二个解决方案中。

关于oop - 具有泛化的类图组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66196231/

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