When to use UML Association Classes?

南楼画角 提交于 2020-01-21 01:44:12

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4744466/when-to-use-uml-association-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!