Class Diagram
On this page
University Course ModelA class diagram shows types, attributes, operations and relationships. Its rectangles have compartments for the class name, data and operations.
+ means public, - private and # protected in UML. Our Python _enrollments and _grade use the internal-use underscore convention; Python does not enforce those UML access levels.
{readOnly} marks a public value that callers read without assigning to it directly.
1 means exactly one; 0..* means zero or more. Plain lines show associations. We use them here because students and courses have independent lifetimes.
University Course Model
Read one box from top to bottom: its class name, attributes, then operations. An attribute such as name : str describes stored text; an operation such as enroll(course) : Enrollment accepts a course and returns an Enrollment. Parentheses identify an operation, while a colon introduces a stated type.
Read a relationship from both directions. The 0..* near Enrollment allows one Student to have zero or many enrollments; the 1 near Student says each Enrollment refers to exactly one Student. The Course relationship works the same way.
Student’s enroll(course) creates an Enrollment and records the same link on both sides. Enrollment holds the grade for that student in that course. Its public grade property is read-only; set_grade controls updates.
Check the model: why would a single grade stored on Course lose information? Trace a second student joining the same course, then inspect the object snapshot.