Interaction Diagrams in UML
Interaction Diagrams in UML (Unified Modeling Language) are used to model the dynamic
behavior of a system. These diagrams focus on how objects interact with each other, showing the
flow of messages, events, and the sequence in which they occur. Interaction diagrams are
essential for understanding the collaboration between different parts of a system.
There are two main types of Interaction Diagrams:
1. Sequence Diagrams
2. Collaboration (Communication) Diagrams
Both types of diagrams are used to model the interactions between objects but in slightly
different ways.
1. Sequence Diagrams
A Sequence Diagram shows how objects interact with each other over time, emphasizing the
sequence in which messages are passed between them. It represents time horizontally and
objects vertically.
Key Elements in Sequence Diagrams:
Objects: Represented by vertical dashed lines.
Messages: Arrows between objects representing communication. The direction of the
arrow indicates the direction of the message.
Activation Bars: Rectangles on the object lifelines that show when an object is active
and performing an operation.
Return Messages: A dashed arrow representing the return of control or result from a
method call.
Lifeline: A vertical dashed line that represents the existence of an object over time.
Sequence Diagram Notation:
Solid Line: Object's lifeline.
Arrow: A message sent from one object to another. The arrow points from the sender to
the receiver.
Activation Bar: A thin rectangle representing the time period during which an object is
performing an action.
Return Arrow: A dashed arrow representing the response or return from a method or
function.
Example: Sequence Diagram for Online Order Processing
Let’s consider an example where a Customer places an order on an E-commerce Website, and
the system processes the order.
lua
Copy
+--------------------+ +------------------+ +----------------+
| Customer | | Website | | Payment |
+--------------------+ +------------------+ +----------------+
| | |
| selectProduct() | |
| ----------------------------> | |
| | |
| | addProductToCart() |
| | ----------------------------> |
| | |
| | |
| | checkout() |
| | ----------------------------> |
| | |
| | |
| | processPayment() |
| | ----------------------------> |
| | |
| | <---------------------------- |
| | confirmOrder() |
| | ----------------------------> |
| | |
| | <---------------------------- |
| | displayOrderConfirmation() |
| <---------------------------- | |
Explanation:
1. The Customer selects a product on the Website.
2. The Website adds the product to the cart.
3. The Customer proceeds to checkout.
4. The Website calls the Payment system to process the payment.
5. After successful payment, the Payment system sends the result back to the Website.
6. Finally, the Website confirms the order and displays an order confirmation to the
Customer.
In this diagram, the Customer, Website, and Payment are objects that interact through a
sequence of method calls (messages), and the activation bars show when these objects are active.