aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Association class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Association class" Watch "Association class" New topic
Author

Association class

Rama Bhargav
Greenhorn

Joined: Mar 25, 2006
Posts: 25
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.
Rama Bhargav
Greenhorn

Joined: Mar 25, 2006
Posts: 25
Anybody, pl reply if I am on the right track or not.
 
Don't get me started about those stupid light bulbs.
 
subject: Association class