Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 229
tan Avatar asked Dec 10 '25 17:12

tan


2 Answers

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.

like image 120
qwerty_so Avatar answered Dec 13 '25 19:12

qwerty_so


You can change the aggregation name to students. And In the java code, teacher class has an array, arraylist or set etc. which name is students. And there is one more thing, is this relation 1 to many or 0 to many(0..*)?

public class Teacher extends StakeHolders{

   public Student[] students;

   public void markAttendance(){

   }
}
like image 36
Oguz Avatar answered Dec 13 '25 18:12

Oguz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!