Module 2: Class & Sequence Diagrams
Module Overview
UML (Unified Modeling Language) diagrams are essential tools for visualizing, specifying, constructing, and documenting software systems. This module focuses on two key UML diagram types: class diagrams and sequence diagrams.
Learning Objectives
- Understand the purpose and components of UML class diagrams
- Create class diagrams to represent object relationships
- Understand the purpose and components of UML sequence diagrams
- Create sequence diagrams to represent object interactions
- Use appropriate UML notation and symbols
What is UML?
UML stands for Unified Modeling Language which is a declarative language used to create visual diagrammatic representations of application components. UML was developed in an attempt to create a universal standard for visually representing software, and thus it is capable of creating many types of diagrams. In this lesson we will be looking at using it to create Class and Sequence diagrams.
PlantUML
We will be using PlantUML, an IntelliJ extension that allows for the creation and parsing of UML diagrams via text. You can access PlantUML's Website for documentation and specific syntax guides.
UML files should be saved with the .puml extension, and should start and end with the @startuml tag and @enduml tag. IntelliJ will then be able to display the UML diagram within the editor as seen below:

Class Diagrams
A class diagram is a visual representation of the structure of an application which shows each of the system's classes, their properties, their methods, and their relationships with other classes. Each class is represented by a box with information about it's properties and methods listed inside:

This example class shows three properties:
- Their access levels, represented by the symbols: + public, - private, and # protected
- The names of the properties
- The value type separated from the name by a :
Next a horizontal line separates the properties from the methods which are listed showing again their access level, method name, and return type, but this time additionally including information about their parameter types within the ()s.
Finally, the name of the class is displayed at the top, centered in bold.
Class Relationships

For now we consider three types of relationships between classes:
- Association: Two class types that interact can be shown to be associated with one-another using the symbol --.
- Aggregation: A special case of association where one related class has ownership over the other. For example a Library class has ownership over the Books it contains. We create this relationship in PlantUML using the symbol --o.
- Composition: A special case of aggregation where the related class(es) depend on the first in order to exist. For example a Customer and their Orders. Without the Customer, the Orders have no meaning. We represent a composition using the symbol --*.
In future lessons we will learn about inheritance relations between classes. At that time it will be useful to know that we can show an inheritance relationship using the --|> symbol.
Check out the Class Diagram page on PlantUML's documentation for more information.
Class Diagrams
What Are Class Diagrams?
Class diagrams are static structure diagrams that show the classes, interfaces, and their relationships in an object-oriented system. They're used to visualize the structure of a system and how different classes relate to each other.
Key Elements of Class Diagrams
- Classes: Represented as rectangles divided into sections for name, attributes, and methods
- Attributes: Properties or data that a class contains
- Methods: Actions or behaviors that a class can perform
- Relationships: How classes interact with each other (association, inheritance, etc.)
- Visibility: Access modifiers indicating who can access elements (public, private, protected)
Relationship Types
- Association: Basic relationship between classes
- Aggregation: "Has-a" relationship where parts can exist independently
- Composition: Stronger "Has-a" relationship where parts cannot exist independently
- Inheritance: "Is-a" relationship showing subclasses and superclasses
- Dependency: One class depends on another
Sequence Diagrams
What Are Sequence Diagrams?
Sequence diagrams are interaction diagrams that show how objects interact with each other over time. They're especially useful for visualizing dynamic behavior and message passing between objects.
Key Elements of Sequence Diagrams
- Lifelines: Vertical lines representing object existence over time
- Messages: Arrows showing communication between objects
- Activation Boxes: Rectangles showing when an object is active
- Combined Fragments: Sections representing conditional behavior (loops, alternatives)
- Return Messages: Dashed arrows showing returns from method calls
Message Types
- Synchronous: Sender waits for response (solid arrow with solid head)
- Asynchronous: Sender doesn't wait (solid arrow with open head)
- Return: Response to a message (dashed arrow with open head)
- Create: Creates a new object (dashed arrow with "create" label)
- Destroy: Destroys an object (marked with an X)
Best Practices
- Keep diagrams focused on specific aspects of the system
- Use consistent notation and naming conventions
- Include only relevant details to avoid clutter
- Arrange elements for readability
- Use tools like PlantUML or Lucidchart for diagram creation
- Update diagrams as your design evolves
Mastery Task 2: Create Class and Sequence Diagrams
Mastery Task Guidelines
Mastery Tasks are opportunities to test your knowledge and understanding through code. When a mastery task is shown in a module, it means that we've covered all the concepts that you need to complete that task.
Each mastery task must pass 100% of the automated tests and code styling checks to pass each sprint. Your code must be your own. If you have any questions, feel free to reach out for support.
In order to visualize and share with others how this app is intended to work, we need to create class and sequence UML diagrams. By now you should have PlantUML added as a plugin to your IntelliJ IDE. We will be using this to create our diagrams.
Each of these puml files are created for you already in the src/resources folder.
Implement a Class Diagram for the Models
Create a class diagram showing each class in the models package, their properties (excluding maxId), and their methods. (You may omit getters). Indicate the type and access level of each property and method you include.
Also, indicate the relationships between the classes including the Role enum. You can use -- as the relationship type beteen Roles and Employees.
Implement a Class Diagrams for the Services
Create a class diagram showing the chain of dependencies stemming from the EmployeeService class. Include methods, their access levels, and use the --> relationship arrow to indicate a dependency between two classes.
Create a Sequence Diagram for the Operation of Sending a Welcome Letter
The actors are provided for you in the CreateWelcomeLetterSD.puml starting file. Assume App calls the sendFormToEmployeeWithId method.
Indicate the name of each method called, and the class that method returns to. (Some methods may return to the same class from which they were called).
Indicate as well the return data type for non-void methods.
Finally, include any alternate routes that may occur where an exception is thrown.
Completion
Run the gradle command:
./gradlew -q clean :test --tests 'com.bloomtech.welcomeletter.MasteryTask_2*'
and ensure all tests pass.
Resources
Practice Exercises
- Create a class diagram for a simple e-commerce system
- Design a sequence diagram for a user authentication process
- Convert existing Java code into class diagrams
- Document a system's architecture using UML diagrams
Next Steps
After completing this module:
- Complete the practice exercises above
- Review the additional resources for deeper understanding
- Move on to Module 3 to learn about Gradle