Reputation: 21
I have a question and answer related to the Object oriented concept and I need help to understand the answer. Below is an example where I have 2 classes 'Student' and 'Course'. I dont need code just the concept of how object model works.
Question: How would I get all the titles of the courses a student is taking?
Answer: From Student, I would traverse the relationship to Course and when I get to the Course I return the title of the Courses.
What does it mean to traverse the relationship? Doesn it mean to create List of objects of Student class inside Course class?
Upvotes: 2
Views: 82
Reputation: 20205
The relationship between Student
and Course
has to be modeled somehow. One possibility is to give each Student
a field Collection<Course> courses
(and expose it through a getter). Traversing this relationship means to get this field, by e.g. calling the getter.
Upvotes: 2
Reputation: 73617
The association between Student
and Course
means that for each instance (object) of Student
there may or not be one or more links to instances of Course
. Formally, a link is defined in UML to be a tuple that identifies the objects at each end.
"Traversing" the association means to find for a Student
all the Course
with which the student is linked. How it is done is not specified, but there are two popular ways to implement this:
Student
object keeps a collection of courses linked with them. In this case, traversing the association would consist of iterating through the collection.Student
and some Course
. Traversing the association would then consist of finding the subset of links with a given Student
at one end, and iterating through this subset to find the linked Course
.Note: traversing is related to the UML concept of navigability. A navigable association from Student
to Course
, means that it's easy to traverse the association in this direction. Navigability can be unidirectional (e.g. if there is no efficient way for a course to find the linked students).
Upvotes: 2