Class Diagrams


Class diagrams serve to illustrate a real-world representation of classes and their relationships.

Goals of a Class Diagram

  • Analyze the requirements in a conceptual model
  • Illustrate a design of a object-orientated software
  • Mode

Class Diagram Example With Overview

an overview of a good class diagram with arrows indicating certain notations Figure 4.1: Example of a good class diagram.

The above diagram represents an overview of what a user would expect to see in a good class diagram. While the diagram contains quite a lot of information, it contains core features such as class attributes, generalizations, abstract classes, stereotypes, etc.

Good Example

Figure 4.2: Another example of a good class diagram that represents the realtionship between a Person and an Employee.

The above diagran consists of 2 classes and 1 interface. This is a good example of a class diagram, for it adheres to all of the rules used in creating class diagrams. In this class diagram, you see that the Person class is a concrete class that contains a name and age attribute, as well as a getName method. Since the Person class implements the UserInterface, it must implicitly define the getName method, in which case, it does. The Employee class extends from the Person class. Therefore, it is considered to a subclass of the superclass Employee

If an instance of the Employee class were to be created, then the employee object would have access to the name and age attributes, as well as the getName method.


Bad Examples

Figure 4.3: An example of a bad class diagram.

The diagram above is an example of a bad diagram, for the Person class is an abstract class when it should be a concrete class. Since the Employee class inherits from the Person class, then both classes should have the ability to be instantiated. The other fault with this class diagram is that Employee two of the same attributes as Person, those of which are name and age. Since Employee inherits from Person, the Employee object would have access to both the name and age attributes.