- 2070 Magh · 7 marks
Map sequence diagram to pseudo code
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.
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.
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
- Each lifeline (object) becomes a class:
OrderTaker,CreditCardAgent,OrderFulfillment,BillingAgent. - Each message becomes a method in the receiver class, and the sender calls it.
- The order of messages (top to bottom) becomes the order of statements in the sender's method.
- 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).
- The return message becomes the return value of the method.
- The variation (credit failure) becomes an
if/else(or an exception) in the sender. - Links between objects become references (fields) that are set up in the constructor.
Pseudocode
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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Explain online order sequence diagram · Object Oriented Analysis and Design, chapter 2
- Development process and mapping design to code · Object Oriented Analysis and Design, chapter 4
All Object Oriented Analysis and Design chapter 4 questions →