4

I'm not really sure about how to distinguish whether I should define a relationship as dependency or association for certain cases.

For example,

class AttendanceSheet { Map<String> students; boolean[] attend; public void addStudent(Student s) { students.add(s.getName(),s.getStudentNumber()); } public void checkAttendance(String name) { //... } } class Student { private String name; private int staffNumber; //more information such as address, age, etc.. Student(String n, int sn) { name = n; studentNumber = sn; } public String getName() { return name.clone(); } public String getStudentNumber() { return studentNumber; } } 

For this case, would Student and Association have association or dependency? enter image description here This is because I'm not sure whether the association must have the actual reference of the object or it suffice to just have certain information that can reach the object (since student id and number is far more enough to know find out which student object it is directing to).

2 Answers 2

3

In your case the <<uses>> is sufficient, because you don't have actual properties of type Student in AttendanceSheet.

As a side note: not using object references and instead just having the studentNumber is - to say the least - an odd design. But I don't know the context.

Sign up to request clarification or add additional context in comments.

2 Comments

It might be odd since I just made up the example just to get the point. Thanks anyway!
I see :-) As a 2nd side note: the stereotype is not needed and you can go with a simple dependency. One might get philosophical when discussing the difference between a simple Dependency and a <<uses>> stereotyped one.
1

On the business level those objects are related, but there is no single preferred method of diagramming this relationship.

Please see Section 9.5.4 of UML specification for more details on the topic, especially Figure 9.12

To be specific those two notations are semantically equivalent (I'm ignoring irrelevant details):

Inline attribute

Attribute as Association

In the first one to keep a traceability you can use an explicit Dependency pretty much the way you did.

Inline with Dependency

One can also consider students as a Shared Aggregation, however it might be also considered an overkill. Not necessary, just showing a possibility for an answer completeness.

Aggregation

You may also consider Qulified associations to indicate a reference to the Student is based on their specific properties. This is pretty much closest to your need. Sorry, I don't know how to achieve such notation in my tool, but you can find more details in Figure 11.37 in Section 11.5 of the aforementioned specification.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.