Activity Diagram

Model workflow and business processes

Overview

Activity diagrams show the workflow or business process of a system. They are similar to flowcharts but have richer notation for concurrency, branching, and swimlanes.

Activity diagrams are useful for understanding complex business logic before designing classes.

Key Concepts

Start/End nodes: Filled circle and bullseye

Activities: Rounded rectangles

Decision nodes: Diamond shapes

Fork/Join: Thick bars for parallel activities

Swimlanes: Partitions showing responsibility

Code Example

java
1/*
2Activity Diagram: Order Processing
3
4     Customer              Order Service           Inventory             Payment
5         │                      │                      │                     │
6         ●                      │                      │                     │
7         │                      │                      │                     │
8    ┌────▼────┐                 │                      │                     │
9    │  Browse │                 │                      │                     │
10    │Products │                 │                      │                     │
11    └────┬────┘                 │                      │                     │
12         │                      │                      │                     │
13    ┌────▼────┐                 │                      │                     │
14    │ Add to  │                 │                      │                     │
15    │  Cart   │                 │                      │                     │
16    └────┬────┘                 │                      │                     │
17         │                      │                      │                     │
18    ┌────▼────┐                 │                      │                     │
19    │Checkout │─────────────────▶                      │                     │
20    └─────────┘            ┌────▼────┐                 │                     │
21                           │ Create  │                 │                     │
22                           │  Order  │                 │                     │
23                           └────┬────┘                 │                     │
24                                │                      │                     │
25                           ┌────▼────┐                 │                     │
26                           │  Check  │────────────────▶│                     │
27                           │  Stock  │            ┌────▼────┐                │
28                           └────┬────┘            │ Verify  │                │
29                                │                 │Inventory│                │
30                                ◆ (fork)          └────┬────┘                │
31                           ┌────┴────┐                 │                     │
32                           │         │                 │                     │
33                      ┌────▼───┐ ┌───▼────┐            │                     │
34                      │Reserve │ │Process │────────────┼────────────────────▶│
35                      │ Items  │ │Payment │            │                ┌────▼────┐
36                      └────┬───┘ └───┬────┘            │                │ Charge  │
37                           │         │                 │                │  Card   │
38                           ◆ (join)  │                 │                └────┬────┘
39                           │         │                 │                     │
40                      ┌────▼────┐    │                 │                     │
41                      │ Confirm │◀───┘                 │                     │
42                      │  Order  │◀────────────────────────────────────────────┘
43                      └────┬────┘
4445                           ◉ (end)
46
47Legend:
48● Start node      ◉ End node
49□ Activity        ◇ Decision
50◆ Fork/Join bar   → Flow
51*/

Shows the order processing workflow with parallel activities (fork/join) and swimlanes for different components.

Best Practices

  • 1.

    Use swimlanes to show responsibilities

  • 2.

    Keep activities at consistent abstraction level

  • 3.

    Show decision points with guards/conditions

  • 4.

    Use fork/join for parallel activities

  • 5.

    Don't overload with too many details

💡 Interview Tips

  • Use to understand complex workflows

  • Helps identify classes and their responsibilities

  • Good for explaining business logic to interviewer

  • Can reveal edge cases and error handling needs

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Activity Diagram - UML | LLD | Revise Algo