何时使用UML关联类? [英] When to use UML Association Classes?

查看:86
本文介绍了何时使用UML关联类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在下面的这两个图上改进设计吗?如果是这样,怎么办?

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?

图1

图2

推荐答案

对于关联类,仅当它们表示具有某些行为和状态的关联时,它们才有意义。查看Article'sSubject。它无非就是来源,目标和身份。您不需要此类关联的类,只需使用具有所有这些属性的纯关联即可。图中还有更多此类不必要的关联类。使用关联类时的另一重要事项是该关联类的每个实例都应具有唯一的源对和目标对。例如,评论不能仅由文章和用户识别-一个用户可能对一篇文章有​​评论,而这是不允许的。

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.

这篇关于何时使用UML关联类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆