Lecture 23: UML Sequence Diagrams
Unit 3: Requirement Analysis and Design (4353202)
Lecture Agenda
- Recap of Class Diagrams
- What is a Sequence Diagram?
- Components of a Sequence Diagram
- Example: User Login Sequence Diagram
- Advantages of Sequence Diagrams
- Key Takeaways
Recap of Class Diagrams
Class Diagrams show the static structure of a system, including classes, their attributes, operations, and relationships. They are fundamental for object-oriented design.
What is a Sequence Diagram?
A Sequence Diagram is a behavioral UML diagram that shows the interactions between objects in a time-ordered sequence. It depicts the objects involved in a scenario and the sequence of messages exchanged between them.
It is particularly useful for understanding the dynamic behavior of a system and how different objects collaborate to achieve a specific functionality.
Components of a Sequence Diagram
- Lifeline: Represents an individual participant in the interaction. (Vertical dashed line with a rectangle at the top)
- Actor: Represents an external entity that interacts with the system. (Stick figure, similar to Use Case Diagrams)
- Message: Represents communication between objects. (Horizontal arrow)
- Activation (Execution Occurrence): Represents the period during which an object is performing an action. (Thin rectangle on a lifeline)
- Combined Fragments: Used to model complex interactions like loops, alternatives, and optional sequences. (e.g., `alt` for alternatives, `loop` for repetitions)
Example: User Login Sequence Diagram
sequenceDiagram
actor User
participant Browser
participant WebServer
participant Database
User->>Browser: Enter Credentials
Browser->>WebServer: POST /login (username, password)
WebServer->>Database: Query user (username)
Database-->>WebServer: Return user details
alt Valid Credentials
WebServer->>WebServer: Authenticate user
WebServer-->>Browser: Login Success (Session ID)
Browser-->>User: Display Dashboard
else Invalid Credentials
WebServer-->>Browser: Login Failed (Error Message)
Browser-->>User: Display Error
end
Advantages of Sequence Diagrams
- Clear Flow of Logic: Provides a visual representation of the order of interactions.
- Detailed Interaction: Shows the messages exchanged between objects and their sequence.
- Debugging & Testing: Helps in identifying potential bottlenecks, errors, and test cases.
- Communication: Facilitates understanding of complex interactions among team members.
- System Behavior: Useful for understanding the dynamic behavior of the system for a specific scenario.
Key Takeaways
- **Sequence Diagrams** show **time-ordered interactions** between objects.
- They depict **lifelines, messages, and activations**.
- Useful for understanding **dynamic system behavior** and **object collaboration**.
- Help in **debugging, testing, and communication** of complex scenarios.
Next Lecture
Topic: UML Activity Diagrams
Q & A
Questions & Discussion

