CS3342 Lecture 5
UML - Sequence Diagram
Sequence Diagram
There is no limit on the number of actor objects or objects per sequence diagram
Sequence Diagram Basic Elements:
Object, message, life-line, condition, execution occurrence...
Main Message Types
Sequence Numbering
in Visual Paradigm
Synchronous Messages
Return Values
Alibaba can talk to the Thief during the magic door is being opened.
Example: Direct Printing (Synchronous Messages and Call) VS Background Printing (Asynchronous Messages and Call)
VS
Caller is blocked vs Caller is not blocked
Object Creation Message
Object Destruction
Delete an object
Example:
Traffic Violations Lookup Screen
Summary:
Condition
usetReceiver (r) when r is not null (r is not null as a condition).
Lost Message ( to black hole!) & Found Message (from black hole!)
Lost messages are those that are either sent but not arrived, or which go to a recipient not shown on the current diagram. Connecting to other functions in another diagram.
Found messages are those that arrived from an unknown source, or from a sender not shown on the current diagram. They are denoted going to or coming from an endpoint element.
Example - Register an Account:
import java.util.*; public class RegisterController { private List _accounts = new ArrayList(); public void register(String name, int age) { Account account = new Account(); account.setId(1); account.setName(name); account.setAge(age); _accounts.add(account); } public List getAccounts(){ return _accounts; } }
Example - POS System:
Example - Lookup Traffic Violation:
Fragment refers/points to another sequence diagram.
They are only for modeling simple combinations of scenarios.
- Alternatives (alt)
- Option (opt)
- Iteration (loop)
- Break (breaks, jumps out of a loop)
- ..etc (There are more)
CombinedFragments - Alternatives (alt) if... else...
Similar to the “switch statements” or if-statement.
CombinedFragments - Option (opt)
CombinedFragments - Break (break)
CombinedFragments - Iteration (loop)
CASE STUDY (Structure of sequence diagram):
Scenario: The application deals with a warehouse with automatic forklift trucks that move pallets.
A technician gives an order specifying only where a pallet is to be moved to.
All loads are placed on pallets that can be moved around automatically in the warehouse.
Since the pallets are moved automatically, the loads must be checked every tenth move at a checking station to make sure that the loads are still stable on the pallets.
We must therefore keep track of how many times a pallet has been moved.
Implementation 1 vs Implementation 2
This structure above is appropriate when:
- the operations can change order
- new operations could be inserted
This structure above is appropriate when:
- nthe operations have a strong connection
- nthe operations will always be performed in the same order
Example:
Structure of Sequence Diagrams
- form a “consists-of” hierarchy, such as country-state-city
- form an information hierarchy, such as document-chapter-section-paragraph-character
- represent a fixed procedural sequence such as advertisement-order-invoice-delivery-payment
- form a (conceptual) inheritance hierarchy, such as animal-mammal-cat
CAN reverse Java code to sequence diagram in VP
Summary:
- In OO Design, we may use sequence diagram is to specify our object interactions.
- We use such diagrams to illustrate how objects invoke the methods of the other objects in the same diagram
- In dynamic modeling, we need to make decisions on whether to use centralized control or decentralized/distributed control.
- To sketch sequence diagrams, we use both basic elements, InteractionUse, and the CombinedFragments
- Sequence diagram helps software designers to communicate effectively with different stakeholders, such as programmers, customers, end-users on the object interactions and behaviors.