---
title: "Map sequence diagram to pseudo code"
subject: "Object Oriented Analysis and Design"
chapter: 4
key: "semester_6/object_oriented_analysis_and_design:order-model-mapping-pseudocode"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/order-model-mapping-pseudocode
site: BCT Engineering
---

# Map sequence diagram to pseudo code

Object Oriented Analysis and Design · Chapter 4: Implementation

- Asked in: 2070 Magh, 7 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/order-model-mapping-pseudocode
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-4

## Question

Present the mapping process for the fig.1 model (the online order processing sequence diagram: OrderTaker, CreditCardAgent, OrderFulfillment, BillingAgent) using object-oriented based pseudo codes for capturing all important aspects of the model diagram.

## Short answer

Each lifeline in the sequence diagram becomes a class; each message becomes a method in the receiver. Synchronous calls wait for returns, asynchronous calls (like triggerBill) run non-blocking. The pseudocode shows OrderTaker calling CreditCardAgent synchronously, then OrderFulfillment, which asynchronously triggers BillingAgent.

## Answer

The sequence diagram has the actor and the objects `:OrderTaker`, `:CreditCardAgent`, `:OrderFulfillment` and `:BillingAgent`, with the messages `submitOrder`, `processCard`, `placeOrder`, `triggerBill` (asynchronous) and `acknowledgeOrder` (return), and a "Credit Failure" variation.

#### Mapping process
1. Each **lifeline (object)** becomes a class: `OrderTaker`, `CreditCardAgent`, `OrderFulfillment`, `BillingAgent`.
2. Each **message** becomes a method in the **receiver** class, and the sender calls it.
3. The **order of messages** (top to bottom) becomes the order of statements in the sender's method.
4. A **synchronous** message becomes a normal call that waits for a result; an **asynchronous** message becomes a non-blocking call (a new thread or a queued message).
5. The **return message** becomes the return value of the method.
6. The **variation** (credit failure) becomes an `if/else` (or an exception) in the sender.
7. Links between objects become references (fields) that are set up in the constructor.

#### Pseudocode

```text
class OrderTaker
    attributes: creditCardAgent, orderFulfillment
    constructor(cca, of)
        creditCardAgent = cca
        orderFulfillment = of
    end constructor
    method submitOrder(order) : Acknowledgement
        approved = creditCardAgent.processCard(order.card, order.total)
        if approved is false then
            return Acknowledgement("Credit failure")   // variation
        end if
        orderFulfillment.placeOrder(order)
        return Acknowledgement("Order accepted")       // acknowledgeOrder
    end method
end class

class CreditCardAgent
    method processCard(card, amount) : boolean
        return bank.authorize(card, amount)            // external bank service
    end method
end class

class OrderFulfillment
    attributes: billingAgent
    constructor(ba)
        billingAgent = ba
    end constructor
    method placeOrder(order)
        reserveStock(order)
        schedulePacking(order)
        billingAgent.triggerBill(order)                // async, no wait
    end method
end class

class BillingAgent
    method triggerBill(order)                          // runs in own thread/queue
        invoice = createInvoice(order)
        send(invoice)
    end method
end class

// Actor / main
billing = new BillingAgent()
fulfil  = new OrderFulfillment(billing)
taker   = new OrderTaker(new CreditCardAgent(), fulfil)
ack = taker.submitOrder(order)
display ack
```

Important aspects captured: the ordering of calls, the responsibilities of each object, the **synchronous wait** for card approval before the order is placed, the **asynchronous** billing trigger that does not delay the customer's acknowledgement, and the alternative path for credit failure.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. When mapping the sequence diagram, what does each lifeline (object) such as :OrderTaker become?
   A. A method
   B. A class
   C. A local variable only
   D. A comment
   Answer: B. Each lifeline becomes a class, e.g. OrderTaker, CreditCardAgent, OrderFulfillment, BillingAgent. (Key point: Lifeline to class)

2. Where is the method for a message such as processCard defined?
   A. In the sender class, called by the receiver
   B. In the receiver class, called by the sender
   C. In a separate global function
   D. In the Actor only
   Answer: B. Each message becomes a method in the receiver class, and the sender calls it. (Key point: Message to method)

3. How is the asynchronous triggerBill message treated in the mapping?
   A. As a blocking call whose result is awaited before the acknowledgement
   B. As a non-blocking call (new thread or queue message) that does not delay the customer's acknowledgement
   C. As a return value of submitOrder
   D. As an if/else branch
   Answer: B. Async messages map to non-blocking calls, so billing runs without making the customer wait. (Key point: Asynchronous message)

4. How is the Credit Failure variation represented in the pseudocode?
   A. By an if/else (or exception) in the sender after processCard returns false
   B. By a new class CreditFailure for every object
   C. By removing the acknowledgement
   D. By making processCard asynchronous
   Answer: A. The alternative path becomes a conditional in OrderTaker.submitOrder, returning a 'Credit failure' acknowledgement. (Key point: Variation as conditional)

## Related in Object Oriented Analysis and Design

- [Explain online order sequence diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aorder-processing-sequence-diagram-explain) — Object Oriented Analysis and Design, chapter 2
- [Development process and mapping design to code](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Adevelopment-process-map-design-code) — Object Oriented Analysis and Design, chapter 4
