EMZETT.
Login

UML class diagram and sequence diagram: Reading and drawing

In short: The class diagram shows a program’s static structure (classes and relationships), the sequence diagram the timing of messages between objects.

In more detail: The UML (Unified Modeling Language) is a drawing language for software designs. In IHK exams and project documentations these two diagrams appear most. They help to agree ideas in the team before programming.

In Depth

Class diagram

A class is a box with three parts: name, attributes, methods.

+--------------------+
|     Customer       |
+--------------------+
| - name: String     |
| - customerNo: int  |
+--------------------+
| + order(): void    |
+--------------------+

Visibility: + public, - private, # protected. Relationships:

  • Association (line): “knows”, with multiplicity (1, 0..*, 1..*).
  • Inheritance (arrow with empty triangle): “is a”.
  • Aggregation (empty diamond) and composition (filled diamond): “consists of”; with composition the part’s lifetime depends on the whole.
  • Dependency (dashed arrow). Abstract classes and interfaces are marked in italics or with <<interface>>.

Sequence diagram

Shows who sends which message to whom and when. At the top stand the lifelines (vertical, dashed) of the participants, time runs downwards. Arrows are calls, dashed arrows replies.

User -> Shop: order(cart)
Shop -> Payment: pay(amount)
Payment --> Shop: ok
Shop --> User: confirmation

With fragments alternatives (alt), loops (loop) and options (opt) are shown.

Which diagram when?

  • Class diagram: data structure and responsibilities.
  • Sequence diagram: flow of a function across several classes/systems (for example login, order).
  • Use case diagram: who uses the system for what?
  • Activity diagram: flow with branches, similar to a flowchart.
  • State diagram: states and transitions (order: new → paid → shipped).

Tips

Draw only what is necessary, name elements as in the code, keep arrow direction consistent and label multiplicities. Tools: draw.io, PlantUML, Mermaid, StarUML, Lucidchart. Text-based tools (PlantUML, Mermaid) can be versioned and embedded in the wiki.

See also: UML, Modelling (UML, EPC, BPMN), IHK project documentation