Search code examples
javaclassmodelumldiagram

Making a simple UML class diagram for a school


I'm trying to create a simple class diagram for a school. Within my class-hierarchy, a school typically consist of two main stakeholders (student & teacher) and many students can be assigned to a teacher. May I know how I can show this relationship?

I have used aggregation and enumeration in my class diagram however, I'm not exactly sure if it's correct. Could you please advise me? enter image description here


Solution

  • Multiplicity: The way you are using multiplicities is correct (as I can foresee it). It means that there must be at least one student per teacher. Without student, there is not teacher. Sounds like a hire and fire school with no permanent teachers.

    Aggregation: You may use the shared aggregation (open diamond) the way you did. It's correct but see my remarks below.

    Enumeration: Regarding the <<enumeration>> you would just need a dependency rather than an association. Unlike relations to classes an <<enumeration>> is kind of a "primitive" which is not represented as object.

    Role names: As @Oguz points out it's a good idea to use role names at the end of the associations. So you would put teacher near Teacher and students (plural because you have 1..*) near Student at the association. These roles would be implemented as attributes.

    Additional remarks on shared aggregation: You must not care much about shared aggregation. As per UML specification it has no common semantics (p. 110 of UML 2.5):

    Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.

    Aggregation is more about lifetime of objects and real life applications are rather rare than often (mainly if you have to be memory aware in terms of cost or security).

    So in your (and most other) case(s) the multiplicity is what you want to show. This is usually more important than showing e.g. a composite aggregation (where the child objects dies with its parent) let alone shared composition.