UML类图依赖关系或关联

时间:2018-03-12 15:11:30

标签: uml class-diagram

我不确定如何区分是否应该将某种关系定义为某种情况下的依赖关系或关联。

例如,

class AttendanceSheet{
Map<String> students;
boolean[] attend;
public void addStudent(Student s)
{
students.add(s.getName(),s.getStudentNumber());
}
checkAttend{//...}
}

class Student{
private String name;
private int staffNumber;
//more information such as address, age, etc..
Professor(String n,int sn)
{
name=n;
studentNumber=sn;
}
public String getName()
{
return name.clone();
}
public String getStudentNumber()
{
return studentNumber;
}
}

对于这种情况,学生和协会会有关联或依赖吗? enter image description here 这是因为我不确定关联是否必须具有对象的实际引用,或者仅仅具有可以到达对象的某些信息就足够了(因为学生ID和数字远远足以知道找出哪个学生它指向的对象。)

2 个答案:

答案 0 :(得分:1)

在您的情况下,<<uses>>就足够了,因为您在Student中没有AttendanceSheet类型的实际属性。

作为旁注:不使用对象引用,而只是让studentNumber - 至少可以说是一个奇怪的设计。但我不知道背景。

答案 1 :(得分:1)

在业务级别上,这些对象是相关的,但没有一种首选的方法来描述这种关系。

有关该主题的更多详细信息,请参见UML specification的第9.5.4节,尤其是图9.12

具体来说,这两个符号在语义上是等价的(我忽略了不相关的细节):

Inline attribute

Attribute as Association

在第一个保持可追溯性的方面,您可以使用明确的依赖性,就像您一样。

Inline with Dependency

还可以将students视为共享聚合,但它也可能被视为过度杀伤。没有必要,只是显示答案完整性的可能性。

Aggregation

您还可以考虑使用 Qulified association 来表示Student的引用基于其特定属性。这几乎与您的需求相近。抱歉,我不知道如何在我的工具中实现这种表示法,但您可以在上述规范的第11.5节中的图11.37中找到更多详细信息。

相关问题