Activity Diagram
UML & System Modelling
Sequence diagrams are great for showing interactions between specific objects, but what if you need to model a complex workflow or business process? For example, how would you diagram the entire process of fulfilling an online order, from receiving the order to shipping the package? This involves multiple steps, conditions, and potentially parallel activities.
Activity Diagrams are UML's version of a flowchart. They are used to model the dynamic aspects of a system, describing the flow of control from one activity to another. They are excellent for modeling business processes, workflows, and complex algorithms.
Core Components of an Activity Diagram
- Action/Activity: A step in the workflow. Represented by a round-cornered rectangle.
- Start Node: The beginning of the workflow. Represented by a small, filled circle.
- End Node: The end of the workflow. Represented by a filled circle inside another circle.
- Decision Node: A point where the path diverges based on a condition (an
if/else
). Represented by a diamond shape with one incoming path and multiple outgoing paths, each with a "guard" condition (e.g.,[approved]
,[rejected]
). - Merge Node: A point where multiple alternative paths converge back into one. Also represented by a diamond, but with multiple incoming paths and one outgoing path.
- Fork Node: A point where the flow splits into multiple concurrent (parallel) activities. Represented by a thick black bar with one incoming path and multiple outgoing paths.
- Join Node: A point where multiple concurrent activities synchronize and merge back into a single flow. Represented by a thick black bar with multiple incoming paths and one outgoing path. The flow cannot proceed past the join until all incoming flows have arrived.
Example: Order Fulfillment Workflow
Let's model the process for fulfilling an order in an e-commerce system.
Workflow:
- The process starts when an
Order is Received
. - A decision is made: Is the payment
[approved]
or[rejected]
? - If rejected, the process ends.
- If approved, two things happen in parallel:
- The
Warehouse
staffPicks & Packs Items
. - The
Billing
departmentSends Invoice
.
- The
- Once both of those activities are complete, the
Shipping
departmentShips Package
. - After the package is shipped, the process ends.
Activity vs. Sequence Diagrams
Here are a few points worth noting when comparing Activity Diagrams to Sequence Diagrams:
Feature | Activity Diagram | Sequence Diagram |
---|---|---|
Purpose | To model a workflow or process (the "how"). | To model interactions between objects (the "who" and "when"). |
Focus | Flow of control from activity to activity. | Flow of messages between object lifelines. |
Key Elements | Actions, Decisions, Forks, Joins. | Lifelines, Messages, Activation Bars. |
Best For | Business process modeling, complex algorithms. | Detailing a single use case, API interactions. |
Activity diagram is a good tool for understanding and communicating complex workflows. They bridge the gap between high-level use cases and low-level class interactions, making them a valuable part of the design process.