OCUP 2 Foundation study materials
OCUP 2 Foundation study resources

Retakes, Grades, and the Association Class Trap

OCUP 2 Foundation · Put your knowledge to work in context.

All case studies

Retakes, Grades, and the Association Class Trap

A university timetable system has Student and Course. A student may retake a course; each enrollment records term, attempt number, grade, and advisor approval. The current model shows an association between Student and Course with multiplicity 0..* at both ends, plus an association class Enrollment attached by a dashed line. A developer proposes deleting Enrollment and adding grade and term as attributes of Student, with a courseCode attribute on the association. The review also finds an 'advises' association between Advisor and Student with role names advisor and advisee, and a derived attribute Student.gpa marked with a slash. The team must decide whether Enrollment is an association class, a plain class with two associations, or a qualified association, and must keep retake history queryable.

1. Is Enrollment better modeled as an association class or as a separate class with two associations? Justify using the multiplicity of the Student-Course link and the retake requirement.

Read the worked answer

Use a reified class (a plain class Enrollment with associations to Student and Course) rather than an association class, because a Student-Course pair can have multiple enrollments (retakes). An association class has at most one instance per link; with multiplicity 0..* on both ends, attaching Enrollment as an association class implies one enrollment per student-course pair, which contradicts the retake requirement. A qualified association can work if the qualifier is (term, attempt) or an enrollment ID: Student to Course with qualifier [term, attempt] and Enrollment as the qualified class. That is acceptable if the tool and team understand qualifiers, but it is less obvious to reviewers. The reified class makes the many-to-many link explicit, allows Enrollment to have its own identity and associations (for example, to Advisor for approval), and keeps history queryable. If you retain the association class notation, add the qualifier and a constraint stating the uniqueness rule.

2. What is wrong with the developer's proposal to put grade on Student and courseCode on the association? Name the UML concepts violated.

Read the worked answer

Grade is a property of the enrollment, not of the Student: one student has many grades across courses and attempts. Moving grade to Student collapses history and makes it impossible to say which course or attempt a grade belongs to. CourseCode is an identifier of Course, not of the link; putting it on the association duplicates Course's identity and invites inconsistency. UML attributes belong to the classifier whose instances they describe, and association-owned attributes are only for data that exists because of the link. The proposal also loses term and attempt, so retake history disappears. The derived attribute Student.gpa should remain derived from Enrollment grades, not stored independently. The correct fix is to keep Enrollment as the owner of term, attempt, grade, and approval, with associations to Student and Course, and to state the uniqueness constraint (student, course, term, attempt).

3. How should the 'advises' association and the derived gpa attribute be modeled so that role names and derivation are unambiguous?

Read the worked answer

Model advises as an association between Advisor and Student with two association ends; set the end names (role names) advisor and advisee, and multiplicities such as Advisor 0..* to Student 0..*. Role names are not attributes and should not appear as attributes in either class. If advising has its own data (start date, load), reify it as an association class or a class Advising with associations. For Student.gpa, prefix the attribute name with / and add a constraint {derived} or an OCL expression that derives it from Enrollment.grade, for example weighted by credits. State the derivation rule in a note or constraint; a slash alone signals derivation but does not define it. Also specify navigability deliberately: if Student does not need to navigate to Advisor, make that end non-navigable. This removes ambiguity for implementers and prevents the model from implying stored duplicates.