何时使用 UML 关联类?
我可以根据下面这两张图改进我的设计吗?如果是这样,怎么办?
我对图表中关联类的使用感到困惑。我应该使用它们吗?
图1
图2
Can I improve my design on these 2 diagrams below? If so, how?
I am confused by the use of association classes in my diagrams. Should I use them?
Figure 1
Figure 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于关联类,只有当它们表示与某些行为和状态的关联时,它们才有意义。查看文章的主题。它无非就是来源、目标和身份。您不需要用于此类关联的类,只需使用具有所有这些属性的普通关联即可。您的图中还有更多此类不必要的关联类。使用关联类时另一个重要的事情是该关联类的每个实例都应该具有唯一的源和目标对。例如,评论不能仅通过文章和用户来识别 - 一个用户可能对一篇文章有多个评论,这是不允许的。
For association classes, they make sense only if they represent associations with some behaviour and state. Look at Article'sSubject. It has nothing more than source, target and identity. You don't need a class for such a association, just use plain association, which has all those properties. There are more such unnecessary association classes in your diagrams. Another important thing when using association classes is that every instance of that association class should have unique source and target pair. For example Comment is not identifiable just by Article and User - one user may have man ycomments on one article and that is not allowed.
关联类用于捕获两个类之间关联的某些特征。这些特征不属于所关联的类,而是属于类之间的关系。
An association class is used to capture certain characteristics of an association between two classes. These characteristics do not belong to the classes being associated but instead belong to the relationship between the classes.