以下是他们关于协会类(class)的演讲幻灯片:
Sometimes associations have attributes or behavior that does not belong solely to the class at either end. We can model this using an association class. Assume the following diagram models the allocation of students to modules.
The attribute
finalMark
does not ‘fit’ into either ‘end’ of the association. In addition, it will be necessary to record more than one mark for each student (for each module) and vice versa. Thus, the attributefinalMark
is an attribute of the association betweenStudent
andModule
.The association class adds an extra constraint in that there can only be one instance of the association class between any two participating objects. Therefore, if we allowed
students
to re-sit modules but we still needed to retain thefinalMark
’s of previousenrolment
s, we could not use an association class and would need to ‘add’ a class, Enrolment, and two more associations.Also a
Customer
andPerformance
example. It needs to be a full class as customer can have many bookings:
我真的很难同意将点符号更改为完整的类。我已经在整个互联网上查看了这一点,但找不到任何使用这种方法的东西。我找到了我的讲师从 (here) 那里获得信息的文章,但即使是对该文章的评论也质疑其正确性。
在尝试他们设定的任务时,这真的让我很头疼,所以我想澄清一下这个问题。
最佳答案
我不同意你的讲师的观点。
事实上,UML 规范明确说明了相反的情况
UML v 2.5 第 199 页
NOTE. Even when all ends of the AssociationClass have isUnique=true, it is possible to have several instances associating the same set of instances of the end Classes.
我认为将关联更改为关联类不会对关联已经施加的约束产生任何影响。
示例关联具有
[1..*]
两端的多样性。这意味着 Student
的每个实例必须注册一个或更多 Module
,但并不是说一个学生不能在同一个模块中注册一次以上。使关联成为关联类并不会突然改变这一点,因此“解决方案”,将关联类更改为与注册类关联的两个关联似乎没有必要。
关于associations - 我的讲师对协会类(class)的看法是正确的还是错误的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48328325/