Forums Register Login

Association class

+Pie Number of slices to send: Send
While drawing the class diagram, if we have two classes in many to many multiplicity with each other, is it mandatory that we need create an assoication class for this? If not, when and why do we create an association class?

As far as I know, association class is created when it can hold additional info. For ex: Consider 2 classes, Student and Course in many to many relation.

1 Student enrolls in 0..* Courses
1 Course can have 0..* Students

Required Navigation is bi-directional.
So programmatically, this will be represented :
1) In class Student, we will have an array/list of Course Types
2) And Course class will have an array/list of Student instances

However, if are required to hold additional fields about this relation like payments made by student for a particular course, we will need to capture this in an association class as this payment info does not fit into Student or Course, because this is an attribute that depends on the association of Student and Course.

Let me name this association class as "StudentCourseDetail"

One Student can have 0..* StudentCourseDetail (Assocation classs) objects
One Course can have 0..* StudentCourseDetail objects

Programmatically, this translates to :
Student class will have an array of StudentCourseDetail
Course class will have an array of StudentCourseDetail
StundetCourseDetail will have 1 studentId, 1 courseId, and some additional attributes that depend on the student to Course relation like payment made by the student for that particular course.

Please correct me if I am wrong and feel free add your insights.
+Pie Number of slices to send: Send
Anybody, pl reply if I am on the right track or not.
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 853 times.
Similar Threads
Hibernate Association
association in java
Hibernate POJOs -- association or no-association ?
Hashing Index
Dependency vs. association ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:10:25.