An example of a class diagram

Let's take a look at an example of a class diagram of a project. Here, we have some grade management software that is used by the teachers and students of a school. The software allows teachers to update the grades of particular students for different subjects. It also allows the students to view their grade. For this software, we have the following classes:

  • Person

Figure: Person class diagram
  • Teacher
Figure: Teacher class diagram
  • Student
Figure: Student class diagram
  • Subject
Figure: Subject class diagram

Here, we have used Visual Studio to generate our class diagram, so the arrows might not match with the arrows that are given in the previous sections. If you are drawing your class diagrams using other drawing software, or if you are drawing by hand, then use the arrows specified in the previous sections.

Let's take a look at the following complete class diagram:

Here, we can see that we have a Person class that has two attributes, a FirstName and a LastName. The Student and Teacher classes inherit the Person class, so we can see that the arrow is hollow. The Student class has two attributes, email and studentId. It also has a method called GetExamGrade (string subject), which takes the name of the subject and returns the grade in char type. We can see that another class, Subject, has a composition relationship with Student. A Student has a list of subjects and the Subject class has three attributes, grade, name, and subjectId. The Teacher class has an email, phoneNumber, and teacherId, which are string, string, and int types respectively. The Teacher class has an association relationship with the Student class, as a teacher has a group of students under them. The Teacher class also has a method called GiveExamGrade, which takes three parameters, studentId, subject, and grade. This method will set the grades on the students' subjects.

Just by looking at the class diagram, we get a clear idea of the system. We know how the subject is related to the student and how students are related to teachers. We also know that a subject's object can't exist without a student object, as they have a composition relationship. This is the beauty of the class diagram.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.98.14