UML Sequence Diagrams
How to destroy an object in sequence diagrams
Put an "x" at the end of the object lifeline to show object destruction.
Basic elements of a sequence diagram (5)
• Actors = stick man • Objects = object bit • Object lifetime = vertical dashed line • Message = Solid horizontal arrow with message name • Activation life = vertical rectangle.
Asynchronous
• Allows the developer to specify that the system does not need to wait for a response, it can get on with something else. • An open arrowhead is used to indicate that a message is asynchronous. • E.g. email, post, social media chat window.
Synchronous
• Allows the developer to specify that the system needs to wait until the receiver has finished processing the message, only then does the system respond. • Represented by a solid line with black arrow. • E.g. verbal conversation, phone
Level of abstraction for sequence diagrams
• At their most abstract, the message flow may be written as a natural language statement e.g. "Ask where the food is" • In less abstract diagrams (approaching design stage), messages correspond to a class calling a public method within another class e.g. askFoodLocation()
What are good and bad things to destroy?
• Good - any temporary object e.g. CAPTCHAS, instances • Bad - any permanent object e.g. people, databases, websites, systems, servers.
What are good and bad things to create?
• Good - things created by the process e.g. records, transaction, receipts, forms, invoices, contracts, emails, texts. • Bad - anything that exists independent of the process e.g. databases, people, website, systems, buildings.
Types of frames in Sequence Diagrams
• Loop - this shows that multiple messages are sent in the same iteration. There is also a UML loop frame guard in a condition is stated. E.g. [While more items] • Alt - used if you want to show several alternative interactions. It contains an operand for each alternative and each alternative has a guard and contains the interaction that occurs when the condition for the guard is met. E.g. [ifCash] and [else]. • opt - if you want to show that several messages are conditionally sent under the same guard. e.g [if Loyalty card not given].
Sequence Diagrams
• They demonstrate how the objects (and actors) collaborate, by showing the messages (signals and data) passed between them. • However, they do not tell you what each object does between receiving a message and replying or sending out new message.