Loading content...
Class diagrams reveal what objects exist in a system—their attributes, methods, and relationships. But software is not static. Objects come to life, collaborate with each other, exchange messages, and orchestrate complex workflows. To understand how a system behaves over time, we need a fundamentally different perspective.
This is where sequence diagrams enter the picture. They model the dynamic side of object-oriented design: the temporal flow of interactions between objects as they fulfill a use case or execute a feature.
By the end of this page, you will understand objects as lifelines—the vertical participants that anchor sequence diagrams. You'll learn how to identify participants, represent their existence over time, and understand the foundational role lifelines play in modeling dynamic behavior.
Consider a simple e-commerce checkout. A class diagram might show Customer, Cart, PaymentProcessor, Inventory, and OrderConfirmation classes. But that diagram doesn't answer critical questions:
PaymentProcessor signal success or failure?These are behavioral questions—questions about how objects collaborate, not what they are. Answering them requires modeling interactions across time.
Class diagrams and sequence diagrams are two sides of the same design. Class diagrams show the structural skeleton; sequence diagrams show that skeleton in motion. A complete low-level design leverages both perspectives to communicate how the system is organized and how it behaves.
The fundamental building block of a sequence diagram is the lifeline. A lifeline represents a single participant in an interaction—an object, actor, or system component—and its existence over the duration of the scenario.
Visual Representation:
A lifeline consists of two parts:
Head (Header Box) — A rectangle at the top containing the participant's name and, optionally, its type. The standard UML notation is objectName:ClassName (e.g., cart:ShoppingCart).
Tail (Dashed Line) — A vertical dashed line extending downward from the header, representing the passage of time. This line is the participant's "life" during the interaction.
Reading the Diagram:
In the diagram above, we have four lifelines:
customer:Customer — An instance of the Customer classcart:ShoppingCart — An instance of the ShoppingCart classpaymentSvc:PaymentService — An instance of the PaymentService classinventory:InventorySystem — An instance of the InventorySystem classTime flows downward. Events higher in the diagram occur before events lower down. This vertical axis is the temporal dimension that distinguishes sequence diagrams from static structural views.
Let's examine each component of a lifeline in detail.
| Component | Description | Example |
|---|---|---|
| Header Box | Rectangle containing the participant's identity. Contains the name and optionally the type. | order:Order |
| Object Name | The specific instance being represented. May be anonymous if the specific identity isn't important. | myCart, aUser, :Cart |
| Type/Class Name | The class or interface the object instantiates. Preceded by a colon. | :ShoppingCart, :IPaymentGateway |
| Dashed Line | Vertical line extending downward, representing the object's existence over time. | — |
| Activation Bar | Narrow rectangle overlaid on the dashed line, showing when the object is actively executing. | Covered in later sections |
Naming Conventions:
The header box follows the pattern objectName:ClassName. Both parts are optional, but at least one must be present:
| Notation | Meaning |
|---|---|
cart:ShoppingCart | Named instance of type ShoppingCart |
:ShoppingCart | Anonymous instance of type ShoppingCart |
cart | Named instance, type unspecified |
paymentGateway:IPaymentGateway | Named instance implementing an interface |
Anonymous instances (using just :ClassName) are common when the scenario involves a single instance of that type, and the specific name doesn't add clarity.
Use named instances (order:Order) when the specific object matters for understanding the scenario—for example, when multiple instances of the same type participate. Use anonymous instances (:Order) when any instance of that type would behave the same way.
While we often think of lifelines as representing objects (instances of classes), the concept is more general. A lifeline can represent any participant in an interaction:
Types of Participants:
cart:ShoppingCartCustomer, :ExternalPaymentAPI:InventoryMicroservice:AuthenticationProviderLoggerActors in Sequence Diagrams:
Actors represent entities outside the system boundary that initiate or participate in interactions. In a checkout scenario, the "Customer" actor triggers the process. The system's objects then collaborate to fulfill the customer's request.
Actors are typically positioned on the left edge of the diagram, as they usually initiate the interaction sequence.
Match your lifeline granularity to your design goal. For low-level design, use concrete object instances. For high-level overviews, use subsystems or services. The right level is one where each lifeline is meaningful and interactions are clear.
The horizontal arrangement of lifelines affects readability and clarity. While UML doesn't mandate a specific order, professional practice follows conventions that enhance comprehension:
Conventional Ordering (Left to Right):
| Position | Typical Participant | Rationale |
|---|---|---|
| Leftmost | Actor or initiating object | The entity that triggers the interaction is placed first, making it clear where the flow begins. |
| Left-Center | Controller or facade objects | Objects that orchestrate the flow typically come early, receiving the initial request and delegating. |
| Center | Domain/business objects | Core entities that perform business logic are positioned centrally. |
| Right-Center | Service or utility objects | Supporting services (validation, calculation, notification) that get called from domain logic. |
| Rightmost | External systems, databases, APIs | Boundary objects that interact with external resources are placed last. |
Why Ordering Matters:
Proper ordering creates a natural left-to-right flow that mirrors the message sequence. Messages travel predominantly from left to right, with responses returning right to left. This visual pattern—resembling reading order in Western languages—makes the diagram intuitive.
When lifelines are poorly ordered, message arrows crisscross chaotically, obscuring the interaction's logic. A well-ordered diagram tells a visual story: "The customer initiates, the controller delegates, the domain objects work, the services assist, and external systems persist."
If your sequence diagram has arrows crossing in all directions, reconsider your lifeline order. Aim for predominantly left-to-right message flow with responses returning. A few crossing arrows are acceptable, but a tangled web signals poor organization.
Not all objects exist for the entire duration of an interaction. Some are created during the scenario, and some are destroyed. Sequence diagrams have specific notation for these lifecycle events.
Object Creation:
When an object is created during the interaction (rather than existing before it starts), its lifeline begins at the point of creation, not at the top of the diagram. A creation message (often labeled with a <<create>> stereotype or constructor name) points to the header box.
Object Destruction:
When an object is destroyed (its lifecycle ends), a large X marks the end of its dashed line. This indicates the object is no longer available for subsequent interactions.
Design Implications:
Modeling creation and destruction explicitly reveals important design decisions:
This explicit lifecycle modeling helps prevent resource leaks at the design level—long before they become runtime bugs.
Only show creation and destruction when they're meaningful to the scenario. If an object is simply used (already exists, continues to exist), its lifeline runs the full diagram height. Focus lifecycle notation on objects whose creation or destruction is an important part of the interaction.
An activation bar (or execution occurrence) is a thin rectangle overlaid on a lifeline's dashed line. It represents a period during which the object is actively executing—processing a method call, performing computation, or waiting for a response it initiated.
When Activation Bars Appear:
An activation bar begins when an object receives a message (method call) and ends when it returns control to the caller. The bar's height corresponds to the duration of that execution.
Visual Representation:
Reading Activation Bars:
In the diagram above:
Client calls processRequest() on Server → Server's activation beginsServer calls query() on Database → Database's activation beginsDatabase returns results → Database's activation endsServer returns response → Server's activation endsActivation bars show the call stack visually. Nested activations (like Server being active while it waits for Database) represent the call hierarchy.
Stacked Activations:
If an object calls itself (a self-call), it creates a stacked activation—a narrower bar nested inside the outer activation. This visualizes recursive calls or internal method decomposition.
Activation bars answer the question: "Who is in control at this moment?" When multiple objects have activation bars at the same vertical position, it indicates they're on the same call stack—the rightmost active bar is currently executing, and the others are waiting.
Let's apply our understanding of lifelines to model a realistic scenario: an e-commerce checkout process.
The Scenario:
A customer clicks "Checkout" on a shopping cart. The system must validate the cart, check inventory, process payment, and create an order confirmation.
Identified Participants (Lifelines):
| Participant | Type | Responsibility |
|---|---|---|
Customer | Actor | Initiates the checkout process |
:CheckoutController | Controller | Orchestrates the checkout workflow |
:ShoppingCart | Domain Object | Contains items to purchase |
:InventoryService | Service | Verifies item availability |
:PaymentGateway | External System | Processes payment transaction |
:Order | Domain Object (created) | Represents the confirmed purchase |
:EmailService | Service | Sends confirmation notification |
Analysis:
This diagram reveals the checkout's structure:
The lifeline ordering creates a readable left-to-right flow, with the customer on the far left and external systems (PaymentGateway) and side-effects (EmailService) toward the right.
We've established the foundation for understanding sequence diagrams by focusing on their primary building block: the lifeline. Here's what we've covered:
objectName:ClassName pattern — Use named instances when identity matters, anonymous when it doesn't.What's Next:
With lifelines established, we need to understand what connects them: messages. The next page explores how objects communicate through synchronous and asynchronous messages, including the crucial concepts of calls, returns, and signals.
You now understand lifelines as the foundational participants in sequence diagrams. You can identify participants, position them for readability, and represent their creation, destruction, and active execution periods. Next, we'll explore the messages that flow between these lifelines.