Activity diagrams are an essential part of the Unified Modeling Language (UML) that help visualize workflows, processes, or activities within a system. They depict how different actions are connected and how a system moves from one state to another. By offering a clear picture of both simple and complex workflows, activity diagrams make it easier for developers and stakeholders to understand how various elements interact in a system.
What is an Activity Diagram?
Activity diagrams show the steps involved in how a system works, helping us understand the flow of control. They display the order in which activities happen and whether they occur one after the other (sequential) or at the same time (concurrent). These diagrams help explain what triggers certain actions or events in a system.
- An activity diagram starts from an initial point and ends at a final point, showing different decision paths along the way.
- They are often used in business and process modeling to show how a system behaves over time.
To deepen your understanding of activity diagrams and their role in system modeling, the System Design Course offers hands-on practice with activity diagram creation.
When to use Activity Diagram?
Activity diagrams are useful in several scenarios, especially when you need to visually represent the flow of processes or behaviors in a system. Here are key situations when you should use an activity diagram:
- Modeling Workflows or Processes: When you need to map out a business process, workflow, or the steps involved in a use case, activity diagrams help visualize the flow of activities.
- Concurrent or Parallel Processing: If your system or process involves activities happening simultaneously, an activity diagram can clearly show the parallel flow of tasks.
- Understanding the Dynamic Behavior: When it’s essential to depict how a system changes over time and moves between different states based on events or conditions, activity diagrams are effective.
- Clarifying Complex Logic: Use an activity diagram to simplify complex decision-making processes with branching paths and different outcomes.
- System Design and Analysis: During the design phase of a software system, activity diagrams help developers and stakeholders understand how different parts of the system interact dynamically.
- Describing Use Cases: They are useful for illustrating the flow of control within a use case, showing how various components of the system interact during its execution.
Activity Diagram Notations
In activity diagrams, the notations are like visual symbols that help represent different elements and actions in a simple way.
1. Initial State
The starting state before an activity takes place is depicted using the initial state.
A process can have only one initial state unless we are depicting nested activities. We use a black filled circle to depict the initial state of a system. For objects, this is the state when they are instantiated. The Initial State from the UML Activity Diagram marks the entry point and the initial Activity State.
For example:
Here the initial state of the system before the application is opened.
2. Action or Activity State
An activity represents execution of an action on objects or by objects. We represent an activity using a rectangle with rounded corners. Basically any action or event that takes place is represented using an activity.
For example:
Consider the previous example of opening an application, opening the application is an activity state in the activity diagram.
3. Action Flow or Control flows
Action flows or Control flows are also referred to as paths and edges. They are used to show the transition from one activity state to another activity state.
An activity state can have multiple incoming and outgoing action flows. We use a line with an arrow head to depict a Control Flow. If there is a constraint to be adhered to while making the transition it is mentioned on the arrow.
For example:
Here both the states transit into one final state using action flow symbols i.e. arrows.
4. Decision node and Branching
When we need to make a decision before deciding the flow of control, we use the decision node. The outgoing arrows from the decision node can be labelled with conditions or guard expressions. It always includes two or more output arrows.
For example:
We apply the conditions on input number to display the result :
- If number is odd then display the number.
- If number if even then display the error.
5. Guard
A Guard refers to a statement written next to a decision node on an arrow sometimes within square brackets.
The statement must be true for the control to shift along a particular direction. Guards help us know the constraints and conditions which determine the flow of a process.
6. Fork
Fork nodes are used to support concurrent activities. When we use a fork node when both the activities get executed concurrently i.e. no decision is made before splitting the activity into two parts. Both parts need to be executed in case of a fork statement. We use a rounded solid rectangular bar to represent a Fork notation with incoming arrow from the parent activity state and outgoing arrows towards the newly created activities.
For example:
In the example below, the activity of making coffee can be split into two concurrent activities and hence we use the fork notation.
7. Join
Join nodes are used to support concurrent activities converging into one. For join notations we have two or more incoming edges and one outgoing edge.
For example:
When both activities i.e. steaming the milk and adding coffee get completed, we converge them into one final activity.
8. Merge or Merge Event
Scenarios arise when activities which are not being executed concurrently have to be merged. We use the merge notation for such scenarios. We can merge two or more activities into one if the control proceeds onto the next activity irrespective of the path chosen.
For example:
In the diagram below: we can’t have both sides executing concurrently, but they finally merge into one. A number can’t be both odd and even at the same time.
9. Swimlanes
We use Swimlanes for grouping related activities in one column. Swimlanes group related activities into one column or one row. Swimlanes can be vertical and horizontal. Swimlanes are used to add modularity to the activity diagram. It is not mandatory to use swimlanes. They usually give more clarity to the activity diagram. It’s similar to creating a function in a program. It’s not mandatory to do so, but, it is a recommended practice.
We use a rectangular column to represent a swimlane as shown in the figure above.
For example:
Here different set of activities are executed based on if the number is odd or even. These activities are grouped into a swimlane.
10. Time Event
This refers to an event that stops the flow for a time; an hourglass depicts it. We can have a scenario where an event takes some time to completed.
For example:
Let us assume that the processing of an image takes a lot of time. Then it can be represented as shown below.
11. Final State or End State
The state which the system reaches when a particular process or activity ends is known as a Final State or End State. We use a filled circle within a circle notation to represent the final state in a state machine diagram. A system or a process can have multiple final states.
How to Draw an Activity Diagram in UML?
Below are the steps of how to draw the Activity Diagram in UML:
Step 1. Identify the Initial State and Final States:
- This is like setting the starting point and ending point of a journey.
- Identify where your process begins (initial state) and where it concludes (final states).
- For example, if you are modelling a process for making a cup of tea, the initial state could be “No tea prepared,” and the final state could be “Tea ready.”
- Think of the steps or actions required to go from the starting point to the ending point.
- These are the activities or tasks that need to be performed.
- Continuing with the tea-making , intermediate activities could include “Boil water,” “Pour tea into a cup”.
Step 3. Identify the Conditions or Constraints:
- Consider the conditions or circumstances that might influence the flow of your process.
- These are the factors that determine when you move from one activity to another.
- Using the tea-making scenario, a condition could be “Water is boiled,” which triggers the transition to the next activity.
Step 4. Draw the Diagram with Appropriate Notations:
Now, represent the identified states, activities, and conditions visually using the appropriate symbols and notations in an activity diagram. This diagram serves as a visual map of your process, showing the flow from one state to another.
Activity Diagram Example
Here’s an example of an activity diagram that shows the process of making an online purchase:
Steps:
- Browse items on the website.
- Select products and add them to the cart.
- Proceed to checkout.
- Enter shipping details.
- Select payment method.
- If the payment is successful, the order is confirmed, and a receipt is generated.
- If the payment fails, the user is prompted to try again.
- End process.
What are the Differences between an Activity diagram and a Flowchart?
An activity diagram is very similar to a flowchart. So let us understand if activity diagrams or flowcharts are any different.
What is a Flow Chart?
An algorithm is like a set of clear instructions to solve a problem, and a flowchart is a picture that shows those instructions.
- When we’re writing computer programs, a flowchart helps us map out the steps of the algorithm to solve the problem.
- Non programmers use Flow charts to model workflows.
- We can call a flowchart a primitive version of an activity diagram.
- Business processes where decision making is involved is expressed using a flow chart.
Example:
A manufacturer uses a flow chart to explain and illustrate how a particular product is manufactured.
Aspect
|
Activity Diagram
|
Flowchart
|
Purpose
|
Represents the flow of control in a system or process, focusing on activities and conditions.
|
Depicts the step-by-step flow of a process or algorithm, focusing on operations.
|
Used In
|
Primarily used in software and systems modeling, especially in UML (Unified Modeling Language).
|
Commonly used in various fields like programming, business, and process mapping.
|
Complexity
|
Can represent both simple and complex workflows, including concurrent processing.
|
Typically used for simpler, linear processes, though can handle limited complexity.
|
Symbols
|
Uses UML symbols like initial nodes, activity nodes, decisions, swimlanes, etc.
|
Uses basic symbols like rectangles (process), diamonds (decisions), and arrows (flow).
|
Concurrency Representation
|
Supports concurrent activities and parallel flows.
|
Does not support parallel processes explicitly; focuses on sequential flow.
|
Do we need to use both the diagrams and the textual documentation?
Let’s understand this with the help of an example:
- Different individuals have different preferences in which they understand something.
- To understand a concept, some people might prefer a written tutorial with images while others would prefer a video lecture.
- So we generally use both the diagram and the textual documentation to make our system description as clear as possible.
Conclusion
In conclusion, Activity Diagrams serve as invaluable tools in system design and analysis, offering a visual representation of dynamic processes within organizations. They are widely utilized to model business processes, illustrate user interactions, and guide software system design. By providing a clear and concise overview of activities, decision points, and interactions, activity diagrams enhance communication among project stakeholders and contribute to effective documentation.