associations - 我的讲师对协会类(class)的看法是正确的还是错误的?

标签 associations uml class-diagram

以下是他们关于协会类(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.

enter image description here

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 attribute finalMark is an attribute of the association between Student and Module.

enter image description here

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 the finalMark’s of previous enrolments, we could not use an association class and would need to ‘add’ a class, Enrolment, and two more associations.

enter image description here

Also a Customer and Performance example. It needs to be a full class as customer can have many bookings:

enter image description here



我真的很难同意将点符号更改为完整的类。我已经在整个互联网上查看了这一点,但找不到任何使用这种方法的东西。我找到了我的讲师从 (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/

相关文章:

ruby-on-rails - Rails EXCEPT 查询(过滤出联合表中存在的记录)

user-interface - UML 是否应该用于创建 GUI?

使用 UML 类图进行数据库设计

c++ - C++类图和{query}

object - 如何在UML中表示共享对象?

mysql - 在 HasOne 关系中获取关联错误

.net - EF - 添加到由 Id 设置的关联

ruby-on-rails - FactoryGirl owns_to 关联和 validates_presence_of 失败 - 外键已关联,但对象未关联

uml - OCL中方法的输入参数的测试类型

c# - 两个接口(interface)和两个类之间的关系。